我在使用Chrome API时遇到问题。具体来说,我似乎无法通过我的上下文菜单onck功能传递任何内容。
var linkSafetyChild = chrome.contextMenus.create({"title":"Is this link safe?","parentId":linkParent,"contexts":[contexts[2]],"onclick":checkScamAdvisorLink});
调用函数:
function checkScamAdvisorLink(info, tab){ alert(info.mediaType); var searchString = "h ttp://www.scamadviser.com/check-website/"; alert(info.linkURL); var siteToCheck = convertURLToSearchableString(info.linkURL); var finalString = searchString.concat(siteToCheck); }
但是当我尝试使用alert(info.mediaType)
和alert(info.linkURL)
访问info对象时,都会返回undefined
。如何将此信息传递给checkScamAdvisorLink
?
上述摘录来自清单中指定的launch.js
。
的manifest.json:
{ "manifest_version": 2, "name":"Hi-Brite Informational Assistant", "description": "This extension provides extended information and performs various helpful actions based on highlighted text. Just kidding, it does nothing", "version": "0.0.0", "browser_action": { "default_icon": "icon.png", "default_popup":"my_popup.html" }, "permissions": ["activeTab", "ht tps://ajax.googleapis.com/", "contextMenus","tabs"], "background":{ "scripts":["launch.js"] }, "content_scripts":[{ "matches": ["ht tps://www.tineye.com/"], "js":["TinyEyeSearch.js"] }]}