Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
How do I make a content script load before another content script (that runs on the same event) in a Firefox extension?

Here's a portion of my manifest.json file:

  "content_scripts": [ {
"js": [ "common.js", "generation.js" ],
"matches": [ "*://www.site.com/*" ],
"run_at": "document_start"
},
{
"js": [ "page_init.js" ],
"matches": [ "*://www.site.com/*" ],
"run_at": "document_start"
},

Here, I want to run "common.js" before "page_init.js", as common.js contains much shared code and global variables and functions that the other content scripts need to function. I have defined common.js before page_init.js in my manifest, and, in Chrome, doing this results in common.js running before all the other content scripts, which is what I need. However, in Firefox, it doesn't seem to do this.

When I run this extension in Firefox, however, page_init throws an error:

ReferenceError: ReferenceError: href is not defined

"href" is a variable that's defined in common.js.

Do I need to make page_init.js run at document_end in order for common.js to fully run, or is there another way? I need them to both run at document_start.

UPDATE:

I managed to resolve the issue by changing the manifests contents to this:

 "content_scripts": [ 
{
"js": [ "common.js", "generation.js", "page_init.js" ],
"matches": [ "*://www.site.com/*" ],
"run_at": "document_start"
},
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

From firefox documentation:

js

An array of paths, relative to manifest.json, referencing JavaScript files that will be injected into matching pages.

Files are injected in the order given. This means that, for example, if you include jQuery here followed by another content script, like this...

It's probably a firefox bug, you may want to report it.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!