basic example of passing variable from popup to content script

3,094 views
Skip to first unread message

ppick...@acumensolutions.com

unread,
Nov 15, 2013, 12:40:02 PM11/15/13
to chromium-...@chromium.org
Hi all,

I am new to chrome extensions and am having trouble with message passing. Does someone have a barebones example of passing a variable value from popup.js to background.js to contentscript.js? I am trying to toggle a feature on the content page by clicking a button in the popup. I would like to know what to include in each of the scripts as well as in the manifest (using V2). Specifically, how do I target the active tab? Thanks in advance!

Paul

This email and its attachments are for the use of the intended recipient(s) only. If you are not the intended recipient, please do not disclose the contents to anyone, but notify the sender by return email and delete this email (and any attachments) from your system. 

Paulie

unread,
Nov 15, 2013, 1:32:15 PM11/15/13
to chromium-...@chromium.org
You don't need to pass message between the popup and the background page. You can call a function in the backgound page from the popup by using the getBackgroundPage() function on chrome.extension like this:

var bgpage = chrome.extension.getBackgroundPage();

bgpage.someBackgroundPageFunction([SOME VARIABLE(S) FROM POPUP]).


As for background to content script google own page on this is perfectly easy to follow I think:

Pick-Aluas, Paul

unread,
Nov 15, 2013, 4:05:47 PM11/15/13
to Paulie, chromium-...@chromium.org
Thanks for that. A working example of at least background.js>contentscript.js would be much appreciated.

--
You received this message because you are subscribed to a topic in the Google Groups "Chromium-extensions" group.
To unsubscribe from this topic, visit https://groups.google.com/a/chromium.org/d/topic/chromium-extensions/Lp4spTcLIi4/unsubscribe.
To unsubscribe from this group and all its topics, 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/8de8b4bd-6e54-4221-bfaf-5e75f7d90c2d%40chromium.org.

Reply all
Reply to author
Forward
0 new messages