Microsoft Edge 扩展中未显示上下文菜单

Context menu not showing up in Microsoft Edge extension

我正在尝试向 Microsoft Edge 浏览器扩展添加上下文菜单项,但它根本没有显示。

我正在使用 Windows 10 Insider Preview Build 14372

我查看了 supported apis 的文档,其中指出 Edge 浏览器支持上下文菜单 API。

manifest.json

{
  "manifest_version": 2,

  "name": "Sample Context Menu",
  "version": "1.0.0",

  "description": "Adds a context menu item when you select some text",
  "author": "author_name",

  "icons": { 
    "16": "icon/icon16.png",
    "32": "icon/icon32.png",
    "48": "icon/icon48.png",
    "128": "icon/icon128.png"
  },

  "permissions": ["contextMenus"],

  "background": {
    "scripts": ["index.js"],
    "persistent": true
  }
}

index.js

chrome.contextMenus.create({
    id: "sample",
    title: "Sample Context Menu",
    contexts: ['selection']
});

chrome.contextMenus.onClicked.addListener(function(info, tab) {
    if (info.menuItemId == "sample") {
        var selected_text = info.selectionText;
        console.log(selected_text);
    }
});

当我查看开发人员控制台时,我收到 Script5007:无法获取 属性 'create' of undefined or null reference 错误消息。

您应该使用 browser.* 而不是 chrome.*