Javascript 在chrome扩展中运行jquery脚本

Javascript 在chrome扩展中运行jquery脚本,javascript,jquery,google-chrome,google-chrome-extension,Javascript,Jquery,Google Chrome,Google Chrome Extension,我正在开发一个需要发送POST http请求的chrome扩展。我有一个发送post请求的短jquery脚本,但我目前正忙于让扩展在单击浏览器操作按钮时运行脚本。我在这里读过其他几个类似的场景,但似乎没有一个适合我 以下是脚本(另存为send.js): 以下是我当前使用的清单: { "name": "plugin name", "version": "0", "description": "What do I do as an extension", "background": {"pa

我正在开发一个需要发送POST http请求的chrome扩展。我有一个发送post请求的短jquery脚本,但我目前正忙于让扩展在单击浏览器操作按钮时运行脚本。我在这里读过其他几个类似的场景,但似乎没有一个适合我

以下是脚本(另存为send.js):

以下是我当前使用的清单:

{
 "name": "plugin name",
 "version": "0",
 "description": "What do I do as an extension",
 "background": {"page": "background.html"},
 "manifest_version": 2,
 "browser_action": {
   "name": "Manipulate DOM",
   "icons": ["icon.png"],
   "default_icon": "icon.png"
 },
 "content_scripts": [ {
   "js": [ "jquery.min.js", "background.js" ],
   "css": ["customStyles.css"],
   "matches": [ "http://*/*", "https://*/*"]
 }]
}
下面是background.js

// this is the background code...

// listen for our browerAction to be clicked
chrome.browserAction.onClicked.addListener(function (tab) {
    // for the current tab, inject the "inject.js" file & execute it
    chrome.tabs.executeScript(tab.ib, {
        file: 'send.js'
    });
});

非常感谢

我建议您使用native
XMLHttpRequest
或native
fetch
而不是要求一个臃肿的慢速库来完成一个简单的
POST
操作,它将解释编写扩展所需的基本知识。至于这个问题,您需要在清单中声明一个背景/事件页面,而不是
内容\u脚本
(请参阅docs链接)。然后看看许可证。
// this is the background code...

// listen for our browerAction to be clicked
chrome.browserAction.onClicked.addListener(function (tab) {
    // for the current tab, inject the "inject.js" file & execute it
    chrome.tabs.executeScript(tab.ib, {
        file: 'send.js'
    });
});