Content Script doesn't run on some Firefox browsers

We are trying to track down something with our Firefox extension. It has a content script that injects some code into the page. On most Firefox 44 browsers, it runs fine. But on a few (one on a Mac, one on Windows 10) it doesn’t seem to run.

As a test, I put a JavaScript alert in the content script and made my own XPI. We put the XPI on these Firefox browsers, and the alert doesn’t show.

Here’s the strange part - on those machines, we create a new Firefox profile. Then the extension works - the content script runs, the alert appears, etc.

So the situation seems to be that creating a new profile suddenly allows the content script to function.

Any thoughts as to what could cause this?

Can you share your code? A minimum verifiable/reproducible example would be ideal if possible.

Sure … this is the entire content script. You’ll see a comment at the bottom on the alert that doesn’t show. In this case, its just there all by itself - when the extension runs, we expect to see it (that alert is for testing only):

window.addEventListener("message", function(event) {

    var addonMessage = event.data;

   if(addonMessage && addonMessage.acFirefoxRequest ) {
        if( addonMessage.acFirefoxRequest === 'acIsScreenSharingAvailable' ) {
            // Request: acIsScreenSharingAvailable
            self.port.emit('acIsScreenSharingAvailable');
        }   
   }

}, false);

// Called by index.js with the version of the extension.  The version is sent back
// to the caller.
self.port.on( 'acIsScreenSharingAvailableResponse', function(version) {
    window.postMessage({
        acIsScreenSharingAvailable: true,
        version: version
    }, '*');
});

// This is the alert that doesn't appear on certain Firefox browsers.  Once
// we create a new Firefox profile, it appears fine.
alert( 'test from extension' );

And the background page looks like this:

var tabs = require("sdk/tabs");
var mod = require("sdk/page-mod");
var self = require("sdk/self");
var pageMod = mod.PageMod({
    include: ["*"],
    contentScriptFile: "./../content-script.js",
    contentScriptWhen: "start", // or "ready"
    onAttach: function(worker) {
        // Message: acIsScreenSharingAvailable.  Respond with the version of the extension.
        worker.port.on("acIsScreenSharingAvailable", function() {
            var version = self.version;
            worker.port.emit( 'acIsScreenSharingAvailableResponse', version );
        });
    }
});

FWIW - we stripped the content script down to just having a single alert, and nothing else.

It still doesn’t work on these 2 profiles on these 2 machines. Once again - if we create a new Firefox profile, everything is fine.

It is possible these users ran Nightly which appears to use the same profile, then ran Firefox 44 again. Is it possible this can leave the profile in a state that might cause some odd behavior like this?

While using a profile in Nightly and then back on Release can cause some problems, I don’t think that would be the case for the add-on problems you’re experiencing. Does the extension appear as installed? Are there any errors in the Console? Have you tried reinstalling the extension in the affected profiles?