nobe4
nobe4

Reputation: 2842

Web browser extension common files

I am building a Chrome/Firefox/Safari extension and I want to reuse the same code on each. I have a background script, an injected script, an iframe, .. And they will be the same for each extension, so I wanted to build something like:

root folder
|- chrome
|  |- manifest.json
|  |- ...
|  \  ...
|
|- firefox
|  \  ...
|
|- safari
|  \  ...
|
\ common
   |- iframe
   |
   |- scripts
   |  |- injectedscript.js
   |  \  backgroundscript.js
   |
   \  ...

So when I add my backgroundscript.js in my manifest.json for chrome like so:

"background" : {
  "scripts" : [
        "../../common/scripts/backgroundscript.js"
    ]
}

But Chrome keep telling me: Could not load background script '../../common/scripts/backgroundscript.js'

Do you know if there is a reason (maybe a Chrome Extension cannot load file in it's parent folder)? And do you think this is a good way to procede?

Upvotes: 1

Views: 72

Answers (1)

Xan
Xan

Reputation: 77541

Chrome extension considers the folder in which manifest.json is as its root. You cannot traverse upwards from there.

Upvotes: 4

Related Questions