主要使用?contextMenus 右鍵菜單功能,正常用它給頁面設置右鍵菜單,其實它也可以給插件還有其它功能設置右鍵菜單,是根據?contexts 選項來設置給哪個功能設置右鍵菜單。
首先添加權限
"permissions": ["contextMenus"],
background.js 添加
chrome.contextMenus.create({id: '右鍵菜單',title: `右鍵菜單`,
});
重新加載插件,?可以看到頁面右鍵時已經有的 右鍵菜單選項
官方關于?ContextType 的解釋
The different contexts a menu can appear in. Specifying 'all' is equivalent to the combination of all other contexts except for 'launcher'. The 'launcher' context is only supported by apps and is used to add menu items to the context menu that appears when clicking the app icon in the launcher/taskbar/dock/etc. Different platforms might put limitations on what is actually supported in a launcher context menu.
取值范圍
"all"
"page"
"frame"
"selection"
"link"
"editable"
"image"
"video"
"audio"
"launcher"
"browser_action"
"page_action"
"action"
?取值為?action 時就是插件的右鍵菜單選項
chrome.contextMenus.create({id: '右鍵菜單',title: `右鍵菜單`,contexts: ['action'],
});