Addons e10s

hello, I would like to ask about the nature of add-ons and e10s.

The idea is to expose and object from add-on script (index.js) to the html page (page.html).

In index.js

function getText() {
return “test”;
}

function f1() {
let domWindow = event.subject;

Components.utils.exportFunction(getText.bind(this, domWindow),
				domWindow.crypto.wrappedJSObject,
				{ defineAs: "getText" });

}

exports.main = function(options, callbacks) {
.
events.on(“content-document-global-created”, f1);
.
var pageMod = require(“sdk/page-mod”);
var data = require(“sdk/self”).data;
pageMod.PageMod({
include: [“file://", "”],
contentScript: ‘window.alert(“Matched!”);’,
contentScriptWhen: ‘ready’
});
}

In page (page.html)

the java script
function getText()
{
var text = window.crypto.getText();
document.getElementById(‘textId’).value = text;
}

the HTML body

<<INPUT type="text" size="10" name="textId" id="textId" value="" readonly>>

The Components.utils.exportFunction does not work for e10s. What is the alternative for the function?

You can’t expose an object from the addon (main script) to html because they are n different processes. You can create an addon script in the content process using frame scripts, but I haven’t done this using the SDK. I don’t even know if it works from the SDK, I suppose it should. A frame script is a privileged script running in the content process so it can directly access web content, and web content can potentially access the frame script subject to security wrappers.

I might suggest that you abandon the idea of letting content call a privileged function. There are so many messaging methods between content and addon scripts now that sending a message may be an easier solution.

What I do is inject a content script. This content script exposes a
function that does send message to the background script and gets back
data. That’s how you establish communication rather then exporting a
function. The only downside (i personally see it as a plus side) is that
the process is now async.

It would help to know which type of addon you have. Content scripts are used in WebExtensions and SDK which have a very specific javascript context and scope (and limitations). In other addons, things called content scripts may be used that are not quite the same.

exportFunction() is a low-level API that is, or soon will be, deprecated. WebExtensions and SDK addons will “just work” in multiprocess Firefox, but not if you use low-level APIs, generally anything you have to “require”.

The end use for an HTML page to access a privileged function (or other object) would also be useful. Presumably the web page is an explicit part of the addon? Might be an entirely different and better way to do that. Exposing any part of privileged code to direct access from content is frowned-upon and might make it difficult to get your addon signed.

I still have no idea on how to start the conversion of my add-on to e10s. First, I need to understand how to inject a content script. And i will worry about the deprecated exportFunction() later.