I’m developing a Firefox (SDK) addon that, at some point, needs to open an internal page (so resource://<addon_id>/data/path/to/some_page.html
) and still be able to retain the ability to communicate with the addon.
Here are the strategies I’ve employed so far but which have all failed.
-
Open a new tab using sdk/tabs.open and hope that, since it’s an internal page, self.port is available in the page’s context to the scripts and they can both listen and emit messages. Didn’t work –
self
isn’t available at all. -
Open a new tab using
sdk/tabs.open
and inject a content script.self
this time is available, however no messages are sent to or received from the addon. This seems to be some sort of security measure. Interestingly the failure to send or receive messages is silent and thus there are no messages dumped to the console. -
Open a new tab using
sdk/tabs.open
, gain direct access to the tab’s (DOM)window
object and send/receive messages via thewindow.postMessage
API. This seems to require invoking getBrowserForTab and then accessing contentWindow.wrappedJSObject. However, invokinggetBrowserForTab
in theonOpened
handler of thesdk/tabs
.open
call returnsundefined
.
I’m stuck.
It seems I’d have a much easier time implementing this with a panel but alas this strategy isn’t available to me as the page needs to be modeless. How can this be achieved?