简体   繁体   中英

chrome extension content script cannot be loaded when using relative path

I met a strange problem which bothered me a lot.

To use the the content scripts, the manifest file is set as:

"content_scripts": [
    {
        "matches": [ ... ],
        "js": [ "a.js", "b.js"]
    }
]

a.js and b.js are put in the root directory of the project. It worked. To organize the project, I moved the two file into a folder, then modified manifest as:

"content_scripts": [
    {
        "matches": [ ... ],
        "js": [ "lib/a.js", "lib/b.js"]
    }
]

Then the extension cannot work and open the dev tool, the content scripts are all empty. If I revoke, then it works again. So what's wrong?

Thank you all!

The extension should work without problems if the scripts are in a folder.

You may do the following to solve this:

  1. Try to reloaded the extension. Navigate to chrome://extensions/ and click the Reload link near the extension;
  2. Be sure that the relative folders are really in the extension root directory;
  3. If you're using Extensions Reloader and made some modification to manifest.json file, then you must manually reload the extension in chrome://extensions/ . Extensions Reloader does not reload changes from manifest.json , but mostly the content script file changes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM