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

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

问题描述

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


  1. 启用开发人员模式

  2. 点击背景页面的链接


  3. 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/.

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

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

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