I’m trying to build an addon for LinkedIn but the contentscript is outputted in every frame…
My main.js:
exports.main = function() {
var pageMod = require("page-mod");
pageMod.PageMod({
include: "http://www.linkedin.com/*",
contentScriptWhen: 'ready',
contentScript: 'alert("test")'
});
};
by doing a check for frame elements i can do an action if its the top frame
if(window.frameElement === null){ alert("YEAH this is the right place!); }
But my content srcipt is complex and uses jquery, and this script still puts the script in every frame…
UPDATE, the SDK’s page-mod api now supports ‘attachTo’, so you can do this instead:
See this more recent question for more info.
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