在Chrome扩展程序中从background.js读取控制台消息的位置? [英] Where to read console messages from background.js in a Chrome extension?

查看:219
本文介绍了在Chrome扩展程序中从background.js读取控制台消息的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用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: p>

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 / 。 p>

Visit chrome://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.

< a href =https://i.stack.imgur.com/rSU9M.png =noreferrer>

这篇关于在Chrome扩展程序中从background.js读取控制台消息的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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