我正在尝试创建一个chrome扩展,它可以删除URL并在一个新的选项卡中打开URL。但是,我始终得到与this (content_script error)相同的错误。我已经按照指示行事了,但我相信我只是不明白自己哪里出了问题。以下是完整的代码:
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>发布于 2011-08-24 03:16:33
它会引发错误,因为您不能在内容脚本中使用chrome.contextMenus.* API。
您不需要用于此任务的内容脚本,只需将所有内容从linkscrub.js移到后台页面(也不需要这些请求)。
https://stackoverflow.com/questions/7170013
复制相似问题