Chrome扩展程序上下文菜单未显示 [英] Chrome extension context menu not showing up
问题描述
我试图将一个上下文菜单项添加到一个Chrome应用程序中,它根本没有显示出来。我读过的所有内容似乎都表明我在这里做的是正确的事情,但显然我没有。
background.js:
var clickHandler = function(e){
console.log('testing testing');
}
chrome.contextMenus.create({
title:Click Me,
contexts:[page,selection,image, link],
onclick:clickHandler
});
manifest.json:
{
update_url:https://clients2.google.com/service/update2/crx,
name:Test,
description:Test,
manifest_version:2,
version:3.2.3,
kiosk_enabled:true,
图标: {
128:icon_128.png,
16:icon_16.png
},
app:{
background :{
scripts:[background.js],
persistent:false
}
},
permissions:[
http:// * /,https:// * /,webview,storage,power,alwaysOnTopWindows,idle,contextMenus
]
}
没有记录错误或类似的东西。该项目根本不显示。我错过了什么?
您错过了便签在 contextMenu
文档中:
函数(可选)
onclick
单击菜单项时将被调用的函数。活动页面不能使用它;相反,他们应该为chrome.contextMenus.onClicked
Chrome会卸载该页面,并且对 所以: I'm trying to add a context menu item to a chrome app and it's not showing up at all. Everything I've read seems to indicate that I'm doing the right thing here, but evidently I'm not. background.js: manifest.json: There are no errors being logged or anything like that. The item simply does not show up. What am I missing here? You missed a small note in the function (optional) You do have an Event page ( Chrome unloads the page, and the reference to So:
这篇关于Chrome扩展程序上下文菜单未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
注册监听器确实有活动页面(persistent):false $ c
clickHandler
的引用可以走开。相反,事件页面机制确保如果您使用 addListener
注册了一个事件,页面将被重新加载, addListener
var clickHandler = function(e){
console.log('testing testing');
chrome.contextMenus.create({
title:Click Me,
contexts:[page,selection, image,link]
});
//必须在事件页面加载时同步调用,
//例如在顶层代码中
chrome.contextMenus.onClicked.addListener(clickHandler);
var clickHandler = function(e) {
console.log('testing testing');
}
chrome.contextMenus.create({
"title": "Click Me",
"contexts": ["page", "selection", "image", "link"],
"onclick" : clickHandler
});
{
"update_url": "https://clients2.google.com/service/update2/crx",
"name": "Test",
"description": "Test",
"manifest_version": 2,
"version": "3.2.3",
"kiosk_enabled": true,
"icons": {
"128": "icon_128.png",
"16": "icon_16.png"
},
"app": {
"background": {
"scripts": [ "background.js" ],
"persistent": false
}
},
"permissions": [
"http://*/", "https://*/", "webview", "storage", "power", "alwaysOnTopWindows", "idle", "contextMenus"
]
}
contextMenu
documentation:
onclick
A function that will be called back when the menu item is clicked. Event pages cannot use this; instead, they should register a listener for chrome.contextMenus.onClicked
"persistent": false
), so it applies to you.clickHandler
can get lost. On the contrary, Event page mechanism ensures that if you registered an event with addListener
the page will be loaded again, addListener
applied again and then your listener executed.var clickHandler = function(e) {
console.log('testing testing');
}
chrome.contextMenus.create({
"title": "Click Me",
"contexts": ["page", "selection", "image", "link"]
});
// Must be synchronously called on event page load,
// for instance in the top level code
chrome.contextMenus.onClicked.addListener(clickHandler);