简体   繁体   中英

Addon attaches script just fine with jpm run, but not with the actual xpi

I'm still fairly new to the addon-sdk and have run into a for me unexplainable problem. So far, I've been using jpm run to test everything - and it all works great. Now, I'm getting close to be finished with what I want to accomplish, so I wanted to give it a test run in a 'normal' browser - mainly to use it over a couple of days to see if everything works as expected.

However, the installing process already throws two error messages:

[Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIURI.hostPort]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: resource://gre/modules/PopupNotifications.jsm :: PopupNotifications_refreshPanel/< :: line 667" data: no] (unknown)

gets thrown twice.

Well, so far, so good (or bad). The toggle-button which my addon adds still shows up. A click on the button opens up a panel which contains a html-page - still working. The panel.html contains a button, and this is the source for my troubles.

If clicked, the button sends a message to my main addon-file:

optionsButton.addEventListener("click", function(){
    self.port.emit("options-clicked");
});

to which index.js listens:

panel.port.on("options-clicked", function () {

    tabs.open("./privacyProtector/options.html");
    panel.hide();

    var optionsTab = tabs[tabs.length - 1];
    var worker = optionsTab.attach({
        contentScriptFile: "./privacyProtector/js/internalOptions.js",
    });

    /* send current settings to options */
    worker.port.emit("initialize", createSettingsJSON());
});

now the options.html tab gets opened (and the panel disappears), but it appears as if the contentScriptFile isn't attached. I tried to figure out exactly where the code stopped working, but haven't been able to. A 'console.log()' after

worker.port.emit("initialize", createSettingsJSON());

works fine, however a 'console.log()' at

self.port.on("initialize", function (message) {
    initialize(message);
});

(which is in internalOptions.js) doesn't appear in the console.

Anyway, the browser console reports:

Use of nsIFile in content process is deprecated. NetUtil.jsm:335:12

< unavailable > timers.js:43

which are errors I have no idea what to do with, because all of this is working perfectly fine with "jpm run". Therefore, I'd be grateful for any help at all, because I have absolutely no idea what's going on here.

If needed, I can also post more code, but I figured this post is already long enough as it is.

Thanks!

Edit: I uploaded the code to github. maybe this makes helping me easier.

https://github.com/Azlond/TrackingProtector

The aforementioned code is in data/privacyProtector/js/panel.js, index.js line 66-91, and data/privacyProtector/js/internalOptions.js

Well, I managed to fix this problem.

Instead of manually attaching the script to the opened tab, I now use pagemod to attach the script whenever the the options page is opened.

var pageMod = require("sdk/page-mod");
pageMod.PageMod({
    include: "resource://protector/data/privacyProtector/options.html",
    contentScriptFile: "./privacyProtector/js/internalOptions.js",
    contentScriptWhen: "end",
    onAttach: sendSettings
});

This way, the options page works perfectly fine. I've encountered a new problem, but I'll ask a new question for it, so that this can be a stand-alone problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM