I have encountered undocumented behaviour in an SDK extension I am currently working on and would appreciate help from the community to find either a fix or a way around it.
The problem only occurs when an HTML page embedded in the extension is opened in a tab, like so:
tabs.open(data.url("html/test.html"));
Note that test.html
above would reside in data/html
from the extension’s root directory.
I’m injecting a content script and listening for messages emitted as given below:
tabs.once("open", function (tab) {
var w = tab.attach({ contentScriptFile: [ data.url("js/embed.js") ]});
w.port.once("init", function () {
console.log("content script initialised");
});
});
The content script, data/js/embed.js
, contains the following:
console.log("attaching embedded script");
self.port.emit("init");
The problem is that if the content script is attached to a data HTML page (a page embedded in the extension), messages sent by the content script are suppressed.
It is absolutely crucial that my extension opens an embedded HTML page and is able to both receive from and send messages to the extension. How can I overcome this limitation?
I’ve created a tiny extension that reproduces the problem clearly. You can find it here.