访问扩展程序background.js的控制台和devtools [英] Accessing console and devtools of extension's background.js

查看:195
本文介绍了访问扩展程序background.js的控制台和devtools的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用Google Chrome扩展程序,但似乎无法从后台js登录到控制台。当发生错误时(例如,由于语法错误),我也找不到任何错误消息。

I just started out with Google Chrome extensions and I can't seem to log to console from my background js. When an error occurs (because of a syntax error, for example), I can't find any error messages either.

我的清单文件:

{
  "name": "My First Extension",
  "version": "1.0",
  "manifest_version": 2,
  "description": "The first extension that I made.",
  "browser_action": {
    "default_icon": "icon.png"
  },
  "background": {
    "scripts": ["background.js"]
  },
  "permissions": [
    "pageCapture",
    "tabs"
  ]
}

background.js:

background.js:

alert("here");
console.log("Hello, world!")

加载扩展程序时,警报出现,但我没有看到任何日志记录到控制台。我在做什么错了?

When I load the extension, the alert comes up but I don't see anything being logged to console. What am I doing wrong?

推荐答案

您在找错地方了。记录的控制台消息不会显示在网页中,而是显示在(不可见的)背景页面中。要在控制台中查看这些消息,请按照下列步骤操作:

You're looking at the wrong place. Logged console messages do not appear in the web page, but in the (invisible) background page. To see these messages in the console, follow these steps:

访问 chrome:// extensions /

也可以右键单击扩展程序图标,然后单击管理扩展名。

Visit chrome://extensions/.
You can also right-click the extension icon, then click "Manage extensions".


  1. 启用开发人员模式

  2. 单击背景页面的链接(在检查视图中)。

  3. 开发人员控制台将打开此页面

  1. Enable developer mode
  2. Click on the link of your background page (at "Inspect views").
  3. The developer console opens for this page.

新用户界面:


旧版UI:

这篇关于访问扩展程序background.js的控制台和devtools的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆