javascript - contextMenu 在 Chrome 打包应用程序中不起作用

标签 javascript google-chrome google-chrome-extension google-chrome-app

我有一个 Chrome 打包应用程序,但我似乎无法弄清楚如何向其添加上下文菜单。

这是我的 list :

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

这是我的 background.js:

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

我做错了什么?当我右键单击时,菜单项没有出现。

谢谢

最佳答案

您可能想查看 Chrome 应用示例,网址为 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

关于javascript - contextMenu 在 Chrome 打包应用程序中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20443648/

相关文章:

javascript - 在 Javascript 中将 JPEG 转换为 SVG

javascript - 为什么会保存sendMessage的内容以及如何禁用它?

javascript - 尝试将 jquery-mousewheel 插件插入 jquery Cycle2

javascript - 使 HTML 表格适合 Bootstrap 对话框

javascript - 无法从 Chrome 扩展访问端点 API

html - Chrome 可滚动 Div 错误

javascript - 如何保存从服务器下载的视频?

javascript - Math.random() 返回值大于一?

google-chrome-extension - Chrome 扩展 - 如何访问本地文件 ://with manifest v3

javascript - 从空 SVG 文档创建 HTML 页面的正确方法