javascriptfirefoxcookiesmozrepl

mozrepl and document.cookie


I'm using mozrepl with firefox 25 on ubuntu and I want to grab the cookies for the current page.

telnet localhost 4242
 ...
 repl> document.title
 "my test cookie site - Mozilla Firefox"
 repl> document.cookie
 repl>

Doing anything with document.cookie and I'm told it is undefined.

Now I know there are cookies b/c when I go to firefox, open up Scratchpad and run alert(document.cookie), I get the expected 2 cookies.

What do I need to do to get the cookies?

Thanks in advance.


Solution

  • First make sure that you are on the page which you want to manipulate with. You can also do this in the repl by

    content.location.href = "http://localhost"
    

    Now when you start, you are in the context of browser window itself, not any particular document. You have access to chrome elements (menus, toolbars, tabs, etc). The document object currently refers to browser window.

    To switch context to the document in active tab use:

    repl.enter(content)
    

    Now that document object is the document loaded in active tab, you have access to its DOM tree and can manipulate it and its cookies.