edge 插件设置右键菜单时报错:
error TypeError: Error in invocation of contextMenus.update([integer|string] id, object updateProperties, optional function callback): Error at parameter 'updateProperties': Unexpected property: 'ItemType'.
at setPopup (background.js:79:31)
at background.js:44:3
contextMenus.update([integer|string] id, object updateProperties, optional function callback): Error at parameter 'updateProperties': Unexpected property: 'wasChecked'.
正确写法:
try {
await chrome.contextMenus.update('弹出框', {
title: `弹出框隐藏`,
type: 'checkbox',
contexts: ['action'],
checked: switchInput
});
} catch (error) {
if (error.toString().indexOf('弹出框') > -1) {
chrome.contextMenus.create({
id: '弹出框',
title: `弹出框隐藏`,
type: 'checkbox',
checked: switchInput,
contexts: ['action']
});
} else {
console.log('error', error)
}
}
chrome.contextMenus.onClicked.addListener(
(info) => {
if (info.menuItemId != '弹出框') return
// console.log('menu click', info)
switchInput = info.checked
chrome.storage.local.set({ switchInput })
}
)