Sar*_*and 1 google-chrome-extension
当用户右键单击 chrome 中的扩展时,有什么方法可以将自定义选项添加到扩展上下文菜单中。任何输入将不胜感激。

更新我尝试过的示例页面操作扩展
Manifest.json
{
"name": "Sample",
"version": "0.1",
"manifest_version": 2,
"background": {
"scripts": ["background.js"]
},
"page_action": {
"default_title": "Sample"
},
"permissions": [
"contextMenus"
]
}
Run Code Online (Sandbox Code Playgroud)
背景.js
chrome.contextMenus.create({
title: "Option22",
contexts: ["page_action"],
onclick: function() {
console.log("click");
}
});
chrome.runtime.onInstalled.addListener(function() {
// Replace all rules ...
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
// With a new rule ...
chrome.declarativeContent.onPageChanged.addRules([
{
// That fires when a page's URL contains a 'g' ...
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { urlContains: 'g' },
})
],
// And shows the extension's page action.
actions: [ new chrome.declarativeContent.ShowPageAction() ]
}
]);
});
});
Run Code Online (Sandbox Code Playgroud)
请检查contextMenus,您可以通过设置上下文来创建扩展上下文菜单"browser_action"
清单文件
{
"name": "36715370",
"version": "0.1",
"manifest_version": 2,
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_title": "Your browser action title"
},
"permissions": [
"contextMenus"
]
}
Run Code Online (Sandbox Code Playgroud)
背景.js
chrome.contextMenus.create({
title: "Your title here",
contexts: ["browser_action"],
onclick: function() {
console.log("click");
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2013 次 |
| 最近记录: |