更新,SDK page-modapi 现在支持“附加到”,因此您可以这样做:
var data = require("sdk/self").data;
var page = require('sdk/page-mod');
page.PageMod({
match:['*'],
contentScriptOptions: {},
contentScriptFile: [data.url('myScript.js')],
attachTo: 'top',
onAttach: function(worker) {
//set up hooks or other background behavior
},
});
See 这个最近的问题以获取更多信息.
There are two approaches you could look into:
1. attach your content scripts using the tabs module. This works because the tabs module only deals with top-level documents. Here is a simple example:
https://builder.addons.mozilla.org/package/22176/latest/
2. do an initial load of a very small content script via page-mod, and then if thepage is something you really want to mod, inject scripts by sending them via port.emit messages. There is an example of this sort of scheme from the dotjs add-on:
https://github.com/rlr/dotjs-addon