jQuery 在 chrome 分机的 background.js 中不工作

jQuery not working in background.js of chrome extension

我正在制作 chrome 延期。这是我的清单:

                {
            "manifest_version": 2,
            "name": "ROBLOX-R",
            "version": "1",
            "description": "An extension to automatically trade currencies.",
            "browser_action": {
                "default_icon": "icon.png",
                "default_popup": "popup.html"
                },
            "permissions": [
                "<all_urls>"
            ],
            "content_scripts": [{
                "matches": ["<all_urls>"],
                "js": [ "jquery.min.js" ]
            }],
            "background": { "scripts": ["background.js"] }
            }

Jquery.min.js 不会加载到 background.js 中使用。我知道这一点,因为如果我在脚本 运行 时转到脚本的后台页面,它会显示 "Uncaught ReferenceError: $ is not defined"。我该如何解决?谢谢

content_scripts 属性 用于 link 脚本和样式表,它们将被注入到您的扩展将处于活动状态的网页上下文中。如果你想在后台页面使用jQuery,你应该将jquery.min.js添加到backgroundscripts 属性:

"background": {
    "scripts": ["jquery.min.js", "background.js"]
}

希望对您有所帮助。