Chrome extension says JS object is undefined

1,705 views
Skip to first unread message

Jason Case

unread,
Mar 4, 2015, 6:17:21 PM3/4/15
to chromium-...@chromium.org
I have a JS object that is defined in the <HEAD>.  If I call it from the console it spits out the objects attributes without issue.  However, if I try to call it from my chrome extension then it says it is undefined.  I even try doing a call back and it is consistently undefined according to the extension but again is fine and dandy in the console.

Does anyone know what permission, setting, or code I might be missing that would cause my extension to not see this JS object?

Thanks,
Jason

Scott Fujan

unread,
Mar 4, 2015, 6:20:59 PM3/4/15
to Jason Case, Chromium-extensions

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/256f66bf-56d7-48bc-97f2-c5ba57c94e1c%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

Jason Case

unread,
Mar 4, 2015, 6:24:20 PM3/4/15
to chromium-...@chromium.org, jca...@gmail.com
Thanks!  So if I understand correctly, there is no way for an Extension to check a value in a JS file loaded from the page unless that JS file somehow passed the needed value to the pages DOM?  


Sean Adams

unread,
Mar 4, 2015, 6:34:03 PM3/4/15
to Jason Case, chromium-...@chromium.org
If you really need to get around it, you can use the content script to inject a script element into the DOM that will execute in the proper context, then use postMessage etc to pass the retrieved value back to your extension.

On Wed, Mar 4, 2015 at 6:24 PM, Jason Case <jca...@gmail.com> wrote:
Thanks!  So if I understand correctly, there is no way for an Extension to check a value in a JS file loaded from the page unless that JS file somehow passed the needed value to the pages DOM?  


--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.

Tom Coleman

unread,
Mar 4, 2015, 6:49:53 PM3/4/15
to Sean Adams, Jason Case, Chromium-extensions
There is also the option of modifying the original page to send messages to the extension.
it is well worth the time to try out all of the message communication stuff.  at first it was pretty tough, but after a few hours of connecting everything your mind starts to see new possibilities.
I'd suggest:
1. add a content script that posts information to a back end / background page
this way the information is fairly permanent.
2. add a popup extension window that shows the information from the background page
3. in the content script, add some visual stuff to the page, showing what it found

Reply all
Reply to author
Forward
0 new messages