Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome extension Chrome扩展:使用Chrome.tabs和Chrome.contextmenu_Google Chrome Extension - Fatal编程技术网

Google chrome extension Chrome扩展:使用Chrome.tabs和Chrome.contextmenu

Google chrome extension Chrome扩展:使用Chrome.tabs和Chrome.contextmenu,google-chrome-extension,Google Chrome Extension,我正在尝试创建一个chrome扩展,它可以清理URL并在新选项卡中打开URL。然而,我一直得到相同的错误。我已经按照指示去做了,但我相信我只是不明白我错在哪里。以下是完整的代码: manifest.json { "name": "Link scrub", "description": "Removes redirectors from links", "version": "0.1", "permissions": ["contextMenus", "tabs"], "

我正在尝试创建一个chrome扩展,它可以清理URL并在新选项卡中打开URL。然而,我一直得到相同的错误。我已经按照指示去做了,但我相信我只是不明白我错在哪里。以下是完整的代码:

manifest.json

{
  "name": "Link scrub",  
  "description": "Removes redirectors from links", 
  "version": "0.1",
  "permissions": ["contextMenus", "tabs"],
  "background_page" : "background.html"
  "content_scripts": [{
    "js" : ["linkscrub.js"]
  }];
}    
linkscrub.js

chrome.contextMenus.create({
    "title" : "Link Trap",
    "type" : "normal",
    "contexts" : ["link"],
    "onclick" : modifyLink
});
 function modifyLink(info, tab) {
    chrome.extension.sendRequest({
        "nurl" = info.linkURL,
        function(response) {
            console.log("linkscrub failed: " + response.farewell)
            }
    });
}
background.html

<script>
chrome.extension.onRequest.addListener(
  function(request, sender, sendResponse) {
    link = "";
    link = sender.nurl;
    link = link.match("url=\b(.*?)&link");
    chrome.tabs.create({
        "url": link,
        "selected" : false
    });
    if(chrome.extension.lastError) 
        sendResponse({farewell : chrome.extension.lastError.message});
    else
        sendResponse({farewell : "Success")};    
  });
<script>

chrome.extension.onRequest.addListener(
功能(请求、发送方、发送响应){
link=“”;
link=sender.nurl;
link=link.match(“url=\b(.*?&link”);
chrome.tabs.create({
“url”:链接,
“选定”:false
});
if(chrome.extension.lastError)
sendResponse({再见:chrome.extension.lastError.message});
其他的
sendResponse({再见:“成功”)};
});

它抛出错误,因为您无法在内容脚本中使用
chrome.contextMenus.*
API


此任务不需要内容脚本,只需将所有内容从
linkscrub.js
移动到您的后台页面(您也不需要这些请求)。

它会引发错误,因为您无法在内容脚本中使用
chrome.contextMenus.
API

此任务不需要内容脚本,只需将
linkscrub.js
中的所有内容移动到您的后台页面(您也不需要这些请求)