简体   繁体   中英

FireFox SDK Addon - “Detach content script” on disable/unload?

I am having some issues trying to figure out how to handle the detach event when the addon is disabled and uninstalled.

In main.js and my content script, I am capturing the "detach" event which fires in both cases, but the content script is not actually removed from the tab. As a result, my listeners and observers continue to fire after the addon is disabled.

My understanding is that destroy() is fired and that should remove the content script, but if I look in the debugger in dev tools, the script is still listed after I disable.

I can remove the listeners and the observers when handling the detach event, but my understanding was that the content script is removed during the detach so the listeners, should be removed?

I also thought to just remove the content script from the DOM, but the content script is not listed if you do something like:

var scripts = document.getElementsByTagName("script");

for (i=0;i<scripts.length;i++){
    if(scripts[i].src == "content-script.js"){
        console.log("content script found");
    }
}

When you do the detach do you need to need to make another call to something to let it know you finished your cleanup? Anytime I capture the detach event in the main.js or my content script, it hangs when rung using cfx ? Is this why its not completing the removal?

My understanding is that destroy() is fired and that should remove the content script, but if I look in the debugger in dev tools, the script is still listed after I disable.

I can remove the listeners and the observers when handling the detach event, but my understanding was that the content script is removed during the detach so the listeners, should be removed?

This is a very good question.

The detach event is event is meant to let you know it's time to clean your content script. Event listeners need to be removed, anything added to the window scope should also be removed,

You don't need to let the main.js script know when you are done.

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