1

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.

Jistanidiot
  • 54,334
  • 4
  • 18
  • 29

1 Answers1

1

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.

Zero Fiber
  • 4,417
  • 2
  • 23
  • 34
  • This seems to work! Once I do the repl.enter(content), how do I switch to another tab. It seems to remain trapped in the tab I did enter(content) even if I click on a different tab. Thanks! – Jistanidiot Dec 10 '13 at 22:47
  • 1
    You can go out of the current tab by using `repl.back()`. Then you can switch to another tab and use `repl.enter(content)` again. – Zero Fiber Dec 11 '13 at 00:32