The script page context cannot use the Chrome API. However, it can send DOM events that can be captured by script content.
The documentation is here . Besides using window.postMessage , you can send custom events .
So you have to make your content script work as a proxy between the page context and the background. Something like that:
// Content script //Listen for the event window.addEventListener("PassToBackground", function(evt) { chrome.runtime.sendMessage(evt.detail); }, false); // Page context var message = {/* whatever */}; var event = new CustomEvent("PassToBackground", {detail: message}); window.dispatchEvent(event);
You can generalize this to convey a response.
Xan
source share