简体   繁体   中英

Troubleshoot Chrome Search Extension

I've been trying to make a basic chrome extension that will search the Wayback Machine based off a link. 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:

{
  "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:

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. I haven't been able to find a beginner resource that provides good examples.

You should change context by contexts in your 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({
    "contexts" : ["link"]
    "title" : "Open link in Archive",
    "onclick" : searchArchive
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM