【问题标题】:console.log not working when creating Chrome extension context menu [duplicate]创建 Chrome 扩展上下文菜单时,console.log 不起作用 [重复]
【发布时间】:2018-02-14 00:56:46
【问题描述】:

我正在编写一个简单的 Chrome 扩展程序,并且一直在阅读 documentation on context menus(即右键菜单)。

我下载了基本示例代码(找到here)并一直在我的浏览器中运行它。提供的示例创建了一个上下文菜单,其中包含一些选项。单击其中一个选项时,一些信息会记录到控制台。

在不更改任何示例代码的情况下,我无法使 console.log() 语句工作。我删除了所有无关代码以创建最简单的版本来重现问题。

function genericOnClick(info, tab) {
  console.log("something");
  alert("something else");
}

var title = "Test 'selection' menu item";
var id = chrome.contextMenus.create({"title": title, "contexts":
["selection"], "onclick": genericOnClick});

manifest.json 如下:

{
  "name": "Context Menus Sample",
  "description": "Shows some of the features of the Context Menus API",
  "version": "0.6",
  "permissions": ["contextMenus"],
  "background": {
    "scripts": ["sample.js"]
  },
  "manifest_version": 2
}

使用上面的代码,右键单击选择会打开一个上下文菜单,其中有一个选项“测试'选择'菜单项”。单击此菜单项将提示“其他内容”,但控制台中不会出现任何内容。

我在控制台中没有收到任何错误。

重申一下,当我下载了here 提供的基本示例并运行它而不做任何更改时,这种行为对我不起作用。

【问题讨论】:

  • 你在访问扩展的控制台吗?

标签: javascript google-chrome google-chrome-extension


【解决方案1】:

查看控制台。有必要检查背景页面。下面的 gif 包含如何执行此操作的示例。

https://i.stack.imgur.com/sw8d5.gif

【讨论】:

  • 天哪,你拯救了我的一天。谢谢你:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-02
  • 1970-01-01
  • 1970-01-01
  • 2012-11-26
  • 1970-01-01
相关资源
最近更新 更多