How to access DOM (and /or window.document object) of a popup in Chrome extension ?

1,447 views
Skip to first unread message

mstram

unread,
Aug 15, 2011, 5:29:30 AM8/15/11
to Chromium-extensions
I'm working on a Google Chrome 'context' script

From the Chrome console, or a 'normal' tag, I can do :

win1 = window.open('some url');
b1 = win1.document.body.innerHTML;

But from a chrome 'context' script, it fails with

Uncaught TypeError: Cannot read property 'document' of undefined

What is the "magic incantation" I need ?

This seems to be close to what I need, but it doesn't show where to
put code to have the popup return a dom element:

http://stackoverflow.com/questions/7063263/how-to-access-dom-and-or-window-document-object-of-a-popup-in-chrome-extension

I don't fully understand the code there (nested scopes and things), so
I'm trying to figure out where I'd put something like:

var getStuff = $('#baz').html();

Maybe some one would like to write a blog post 'disecting' that
code ? :)

Mike

Mike Stramba

unread,
Aug 15, 2011, 5:38:26 AM8/15/11
to Chromium-extensions

mstram

unread,
Aug 16, 2011, 1:09:17 PM8/16/11
to Chromium-extensions
Anybody ???

I'd really like to get this going !

I've looked through all the code examples, and the closest thing is
the "mappy" thing, but it's using a pre-defined "popup", where I need
to access a varying url.

The mappy example also does not have the background page reading FROM
the popup, which is what I need.

Mike

On Aug 15, 5:29 am, mstram <mikestra...@gmail.com> wrote:
> I'm working on a Google Chrome 'context' script
>
> From the Chrome console, or a 'normal' tag, I can do :
>
> win1 = window.open('some url');
> b1 = win1.document.body.innerHTML;
>
> But from a chrome 'context' script, it fails with
>
> Uncaught TypeError: Cannot read property 'document' of undefined
>
> What is the "magic incantation" I need ?
>
> This seems to be close to what I need, but it doesn't show where to
> put code to have the popup return a dom element:
>
> http://stackoverflow.com/questions/7063263/how-to-access-dom-and-or-w...

mstram

unread,
Aug 16, 2011, 1:09:57 PM8/16/11
to Chromium-extensions
Sorry, accidentally sent.

On Aug 15, 5:38 am, Mike Stramba <mikestra...@gmail.com> wrote:
> http://supercollider.dk/2010/04/chrome-extensions-for-web-hackers-par...

Reply all
Reply to author
Forward
0 new messages