contextMenu在Chrome Packaged App中不起作用

contextMenu not working in Chrome Packaged App

本文关键字:不起作用 App Packaged Chrome contextMenu      更新时间:2024-04-30

我有一个Chrome Packaged应用程序,似乎不知道如何添加contextMenu。

这是我的清单:

{
  "name": "Dialer",
  "version": "0.1",
  "manifest_version": 2,
  "permissions": [
    "contextMenus",
    "audioCapture"
  ],
  "app": {
    "background": {
      "scripts": ["background.js"]
    }
  },
  "icons": {
    "128":"icon_128.png"
  }
}

这是我的背景.js:

chrome.app.runtime.onLaunched.addListener(function() {
    chrome.contextMenus.create ({
        title: "%s", 
        contexts: ["all"],
        id: "right-click"
    });
});

我做错了什么?右键单击时,菜单项不会显示。

感谢

您可能想在https://github.com/GoogleChrome/chrome-app-samples/tree/master/context-menu了解它是如何工作的。

正如你所看到的,上下文菜单将出现在你的Chrome应用程序窗口中:

chrome.app.runtime.onLaunched.addListener(function() {
  chrome.app.window.create('main.html', {bounds:{ width: 300, height: 300}});
});
chrome.runtime.onInstalled.addListener(function() {
  // When the app gets installed, set up the context menus
  chrome.contextMenus.create({
    title: 'Click on me',
    id: 'contextMenuId',
    contexts: [ 'all' ]
  });
});

如果你正在Chrome浏览器中寻找上下文菜单,你可能想创建一个Chrome扩展。看见http://developer.chrome.com/extensions/contextMenus.html