使用相对路径时无法加载chrome扩展程序内容脚本 [英] chrome extension content script cannot be loaded when using relative path

查看:104
本文介绍了使用相对路径时无法加载chrome扩展程序内容脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个奇怪的问题,使我非常困扰.

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和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"]
    }
]

然后该扩展程序无法工作,无法打开dev工具,内容脚本全部为空.如果我撤消,那么它将再次起作用.那怎么了

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?

谢谢大家!

推荐答案

如果脚本位于文件夹中,则扩展名应该可以正常工作.

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

您可以执行以下操作来解决此问题:

You may do the following to solve this:

  1. 尝试重新加载扩展.导航到 chrome://extensions/,然后点击扩展程序附近的 Reload 链接;
  2. 确保相对文件夹确实在扩展根目录中;
  3. 如果您使用的是扩展程序加载器和对 manifest.json 文件进行了一些修改,那么您必须手动将扩展名重新加载到 chrome://extensions/中.扩展程序重新加载程序不会从 manifest.json 重新加载更改,但是大部分内容脚本文件都会更改.
  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.

这篇关于使用相对路径时无法加载chrome扩展程序内容脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆