我正在使用
我在
为什么会发生这种情况?
chrome.contextMenus.create
函数在我的Chrome扩展中创建右键菜单。但它创建了额外的选项。我在
manifest.json
文件中授权,在background.js
文件中添加了这个函数,并将其添加到我的manifest.json
文件中。为什么会发生这种情况?
function getword(info,tab) {
console.log("Word " + info.selectionText + " was clicked.");
chrome.tabs.create({
url: "http://www.google.com/search?q=" + info.selectionText,
});
}
chrome.contextMenus.create({
title: "Search: %s",
contexts:["selection"],
onclick: getword,
});
chrome.contextMenus.create
?我猜您没有将函数包装到类似于chrome.runtime.onStartup
事件中,这会导致每次激活扩展时都会调用该函数。 - Haibara Ai