在Chrome扩展程序中从background.js中读取控制台消息的位置? [英] Where to read console messages from background.js in a Chrome extension?
问题描述
我刚刚开始使用Google Chrome扩展程序,我似乎无法从我的后台js登录控制台。当出现错误(例如由于语法错误),我也找不到任何错误消息。
我的清单文件:
{
name:My First Extension,
version:1.0,
manifest_version:2,
description:我创建的第一个扩展名。,
browser_action:{
default_icon:icon.png
} ,
background:{
scripts:[background.js]
},
permissions:[
pageCapture,
tabs
]
}
background.js:
alert(here);
console.log(Hello,world!)
警报出现,但我没有看到任何记录到控制台。我做错了什么?
你看错了地方。记录的控制台消息不会显示在网页中,但在(不可见)背景页面中。要在控制台中查看这些消息,请按照下列步骤操作:
访问 chrome:// extensions /
p>
- 启用开发人员模式
- 点击背景页面的链接
- Enable developer mode
- Click on the link of your background page (at "Inspect views").
- The developer console opens for this page.
a href =https://i.stack.imgur.com/rSU9M.png =nofollow noreferrer>
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.
My manifest file:
{
"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:
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:
Visit chrome://extensions/
.
这篇关于在Chrome扩展程序中从background.js中读取控制台消息的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!