Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Cookies and Webviews again

How do I make a cookie obtained via an httpclient request get used in a subsequent webview?

A previous 'answer' merely stated that the respondent had found a way to enter the cookies into a webview.db by reading the older support forums.

These are no longer available, there is of course nothing in the documentation, can anybody tell me anything about a webview database?

Thanks,

JH

— asked April 29th 2010 by John Holman
  • cookies
  • webview
  • webview.db
0 Comments

2 Answers

  • 10 months later, same question.
    How to manually set a cookie for a given host for WebView?

    — answered February 14th 2011 by Thomas Dall'Agnese
    permalink
    1 Comment
    • with javascript… your question is different from this original question

      — commented February 14th 2011 by Aaron Saunders
  • i am also struggling with this (the original question) using android. not the webview database part, but attempting to use a xhr cookie in a webview. this is what i have done so far:

    in my xhr.onload:

    Ti.App.my_cookie = xhr.getResponseHeader("Set-Cookie");
    

    then in webview.beforeload:

    webview.evalJS("document.cookie="+Ti.App.my_cookie+";");
    

    but it always hangs on setting the cookie, showing a line like this in the android emulator log:

    D/TiWebViewBinding( 1369): (main) [4,5966] getJSValue:javascript:_TiReturn.setValue((function(){try{return document.cookie=cookie_monster=blahblah; path=/; HttpOnly;+"";}catch(ti_eval_err){return '';}})());
    

    i am not sure where the

    ;+"";
    

    in the log comes from, and maybe that is messing stuff up, but if i set it to an empty cookie (evalJS("document.cookie=")) it doesn't hang and shows a log with:

    {try{return document.cookie+"";}
    

    and the cookie is empty.

    so… more of another question than an answer, is this not working the way it's supposed to, or am i doing something wrong?

    — answered September 14th 2011 by Jay Becker
    permalink
    2 Comments
    • that inline comment apparently doesn't like quotes, supposed to look like:

      evalJS("document.cookie=")
      

      — commented September 14th 2011 by Jay Becker
    • of you ask me
      webview.evalJS("document.cookie="+Ti.App.my_cookie+";");
      Schould be
      webview.evalJS("document.cookie='"+Ti.App.my_cookie+"';");
      The cookie is a string and must have quotes

      — commented April 23rd 2012 by Gert Vanbeckevoort
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.