1

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

我正在使用 Windows 10 Insider Preview Build 14372

我查看了受支持 api 的文档,其中说 Edge 浏览器支持 contextMenus API。

清单.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: Unable to get property 'create' of undefined or null reference错误消息。

4

1 回答 1

2

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

于 2016-06-24T07:16:35.100 回答