I am running into an issue sending data from my background script to the script for my pageAction
. My content script adds an <iframe />
and the JavaScript in the <iframe />
is receiving the data from my background script, but it does not seem to be retrieved in my pageAction
.
In my background script I have something like:
chrome.tabs.sendMessage(senderTab.tab.id,
{
foo:bar
});
where senderTab.tab.id
is the "sender" in onMessage
Listener in my background script.
In the JavaScript loaded by the <iframe />
injected by my content script I have something like:
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log("received in iframe:", request);
}
});
The <iframe />
receives the message exactly as expected.
I put the same JavaScript in my page_action.js
, but it does not receive any data from the background script. The pageAction is activated with chrome.pageAction.show(senderTab.tab.id);
before I call chrome.tabs.sendMessage(senderTab.tab.id ...
Is the HTML page attached to my pageAction not part of the same tab? Since this tabId
enabled me to activate/"show" the icon, I would think the listener in the JavaScript for the pageAction should also receive from chrome.tabs.sendMessage(senderTab.tab.id ...
In my content script I use the following to send data to the background script:
chrome.runtime.sendMessage({
foo: bar
});
When the content script sends the above message, the pageAction JavaScript is picking it up.
How do I get the background script to properly send data to my pageAction? I do not want to have pageAction request/poll, instead I want pageAction to just listen and receive. E.g., if the pageAction HTML it shown, it should be able to update in real time as the background page makes changes.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…