Content script detect when it's tab gets focus

547 views
Skip to first unread message

patrick

unread,
Sep 26, 2011, 5:08:06 PM9/26/11
to Chromium-extensions
Simple question.... I need my content script to run a method when the
page tab get's focus. Can I do this in the content script itself? Or
do I need the background page to listen for the onSelectionChanged
event and send a message to the relevant content script?? (sorry if
it's a silly question! : )

x29a

unread,
Sep 26, 2011, 5:21:55 PM9/26/11
to Chromium-extensions
hi patrick,

as you can read here:

http://code.google.com/chrome/extensions/dev/content_scripts.html

content scripts cannot access most of the chrome.tabs API so you will
need to use

http://code.google.com/chrome/extensions/messaging.html

to deliver the needed information. if its just about the tab.id, maybe
this post will help you:

http://stackoverflow.com/questions/6202953/obtaining-this-tab-id-from-content-script-in-chrome-extension

no problem to ask a "silly question", as long as you tried solving it
for yourself first by e.g. a search on stackoverflow or the docs ;)

Chiuto

unread,
Sep 26, 2011, 8:04:39 PM9/26/11
to patrick, Chromium-extensions
yes you need the background page.
it is the permission design of contentscripts


--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


Reply all
Reply to author
Forward
0 new messages