Frame script with FF 44

I’m testing a new version of my add on with nightly, and it works (as far
as I can see).

When I try this version on the current FF (44.02), it seems that several
instance of the the same frame.js file are attached to the same page…

My add on insert string in a search field on the web page when a message is
received from the browser thread, and the same insert is done several time.

Thanks for any advice
fra

You may be adding the frame script multiple times, or perhaps only once and then activating it several times. Adding frame scripts works fairly reliably, including in the current release version. Given that it is 99% certain to be a bug in your code, we really need to see the code.

Here’s a simple example of a framescript addon - https://github.com/Noitidart/Full-Stop

@Lithopsian
The whole code is here:
https://sourceforge.net/p/filteredclipboard/code/ci/default/tree/chrome/content/

I load the frame script in the file scope of browser.js with
Components.classes["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager).loadFrameScript(“chrome://filteredclipboard/content/frame.js”,
true);
The browser.js file is loaded in the browser.xul with .
The xul file is declare as an overlay in the chrome manifest
overlay chrome://browser/content/browser.xul
chrome://filteredclipboard/content/browser.xul

Thanks
F.

And there’s your problem. The global message manager loads a frame script into every tab in every window. A separate instance of browser.xul is run in every window. You are loading the frame script multiple times.

Thanks, but why (as it seems) is this happening in FF44 and not in Nightly ?

Trust me, it is broken in both versions. You may see different symptoms in different circumstances due to changes in things like which documents get remoted. I haven’t looked into it in detail, but if you have a lot of time on your hands feel free to dig into why you can sometimes get away with it :wink: You should be able to easily demonstrate problems in either version by opening several windows and seeing how many frame script messages you get.

I had a quick look at the actual code and spotted something else that you should probably change. All the frame script loading and message listeners would be much more reliable after the window load event fires. I guess it kind of works now or you wouldn’t have got this far, but there is no guarantee that it will always work, or even that it will work now on all platforms or simply in different installs. For example, there is no guarantee that the window global has a messageManager property that early (hint, use it for loading the frame scripts). Or it might work now and break tomorrow. The same for everything else really, you are riding your luck doing anything before that window load event. Sometimes it will work, then sometimes it will break and you’ll be killing yourself trying to work out why.

Yes: with further testing, I see that even with Nightly I have the same
number of repeats then of opened browser windows when I use the Global MM.

I will load of the frame script and register the message listener in a
function that is called on window.load.

Thanks again

F.