Order of execution of content scripts in Mozilla web extension

I have a Chrome+Mozilla web extension, Requestly. I load two content scripts for a particular page with the following declaration in manifest

"content_scripts": [
    {
      "matches": [ "*://requestly.in/rules/*" ],
      "css": [ "generated/pages/css/main.css" ],
      "js": [ "generated/pages/js/libs.js", "generated/pages/js/main.js" ]
    }
  ],

With this declaration, I assumed main.js should be executed after libs.js is executed because main.js is dependent on libs.js

libs.js contain libraries
main.js contain app specific code

But I am getting an error on the page saying ‘taostr’ is undefined which is defined in libs.js and used in main.js

I put console logs at the beginning and end of both the scripts to ensure the order of execution and I found a strange behavior.

Here is the screenshot showing the execution is either parallel or out of order.

Can you please confirm what I expect is wrong or not ? Why did main.js started execution first even before libs.js has not started ?

This used to work before Firefox v52.

As far as I know, there is no guarantee of the order in which scripts will be loaded. You may need to rely on the load event or a timeout to make sure both scripts have been loaded.

https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json/content_scripts says that they are injected in the order specified, and gives an example.

In that case, it must be a bug. Adding @wbamberg to confirm that part of the documentation matches the implementation.

Chrome docs: https://developer.chrome.com/extensions/content_scripts#js

Unless this is an intentional incompatibility with Chrome behavior, then the docs are correct and this is a Firefox bug.

@wbamberg @jorgev One more thing, the same scripts work in Chrome stable as well as Canary version So I strongly believe this is a Firefox bug.

Also, Instead of using timeouts or load event, I’d prefer to concatenate them in order and avoid this situation.

Due to this, my extension is broken on Firefox. I’ll do the workaround. Please update this thread once you officially confirm this is a Firefox bug.

It sounds like a Firefox bug. Can you please file it here: https://bugzilla.mozilla.org/enter_bug.cgi?product=Toolkit&component=WebExtensions:Untriaged

Thanks @jorgev. I have logged a bug here: https://bugzilla.mozilla.org/show_bug.cgi?id=1347700