[英]Troubleshoot Chrome Search Extension
I've been trying to make a basic chrome extension that will search the Wayback Machine based off a link. 我一直在尝试制作一个基本的chrome扩展程序,该扩展程序将根据链接搜索Wayback Machine。 I'm trying to set it up so that when I right-click a link, the context menu has a 'go to wayback machine' option. 我正在尝试对其进行设置,以便当我右键单击一个链接时,上下文菜单具有“转到后退机器”选项。 This is what I have: 这就是我所拥有的:
manifest.json: manifest.json:
{
"name" : "Archive Right Click",
"manifest_version" : 2,
"version" : "1.0",
"description" : "Adds Go to Archive to right-click context menu.",
"icons" : {
"16" : "icon-16.png",
"48" : "icon-48.png"
},
"browser_action" : {
"default_icon": "icon-16.png",
"default_title" : "Go to Archive"
},
"permissions" : [
"tabs",
"contextMenus"
],
"background" : {
"scripts" : ["script.js"]
}
}
script.js: script.js:
function searchArchive(info,tab) {
var url = info.linkUrl;
var archiveURL = "https://web.archive.org/web/*/" + url;
chrome.tabs.create({
url : archiveURL,
});
}
chrome.contextMenus.create(
{
"context" : ["link"],
"title" : "Open link in Archive",
"onclick" : searchArchive
});
The problem is that it doesn't even show up in the context menu let alone open the tab I want. 问题在于它甚至没有显示在上下文菜单中,更不用说打开我想要的选项卡了。
Let me know about any useful tutorials on chrome extensions. 让我知道关于chrome扩展的任何有用的教程。 I haven't been able to find a beginner resource that provides good examples. 我找不到能够提供良好示例的初学者资源。
You should change context
by contexts
in your script.js 您应该在script.js context
按contexts
更改context
function searchArchive(info,tab) {
var url = info.linkUrl;
var archiveURL = "https://web.archive.org/web/*/" + url;
chrome.tabs.create({
url : archiveURL,
});
}
chrome.contextMenus.create({
"contexts" : ["link"]
"title" : "Open link in Archive",
"onclick" : searchArchive
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.