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

时间:2016-06-24 06:17:11

标签: javascript contextmenu microsoft-edge microsoft-edge-extension

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

我正在使用Windows 10 Insider Preview Build 14372

我查看了supported apis的文档,其中说明了Edge浏览器支持contextMenus 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:当我查看开发者控制台时,无法获取未定义或空引用的属性“创建”错误消息。

1 个答案:

答案 0 :(得分:2)

您应该使用$(document).ready(function(){ $('#insertedDiv).insertAfter("#firstDiv"); }); 代替browser.*