Reputation: 31
I have a var
in background page (for example var x = 23
). How I can get this variable in my content script? I tried this in content.js
:
chrome.extension.getBackgroundPage().x;
But it doesn't work.
Upvotes: 3
Views: 2688
Reputation: 18534
You can not use chrome.extension.getBackgroundPage()
in content scripts, it is not supported, as an alternative use epoch answer for message communication.
Upvotes: 1
Reputation: 16605
Send your data with messages, and listen on the receiving side.
Since content scripts run in the context of a web page and not the extension, they often need some way of communicating with the rest of the extension. For example, an RSS reader extension might use content scripts to detect the presence of an RSS feed on a page, then notify the background page in order to display a page action icon for that page.
Upvotes: 4