简体   繁体   English

我的chrome扩展程序不会向控制台显示错误,但会显示日志

[英]My chrome extension doesn't show errors to console, but it shows logs

I've encountered an issue that drives me completely nuts. 我遇到了一个让我完全疯狂的问题。

My chrome extension doesn't report any errors to Developer Tools console. 我的chrome扩展程序不会向Developer Tools控制台报告任何错误。 BUT: it still writes logs, works generally well, and the non-extension scripts on the page still report their errors. 但是:它仍然会写日志,工作得很好,页面上的非扩展脚本仍会报告错误。

I've seen some words that extension's errors can be displayed in popup.html's DevTools window, but my extension doesn't (and can't by design, it is made for parsing other pages) use that popup.html at all. 我已经看到一些单词,扩展的错误可以在popup.html的DevTools窗口中显示,但是我的扩展没有(并且不能通过设计,它是用于解析其他页面)使用popup.html。

The worst thing is that even syntax errors (!) of extension are not displayed. 最糟糕的是,甚至没有显示扩展的语法错误(!)。 I'd be infinitely and eternally grateful if you could give me the solution for this problem, for it is a huge pain in the ass debugging an extension without syntax errors notifications : ( 如果你可以给我解决这个问题的解决方案,那将是无限和永远的感激,因为在没有语法错误通知的情况下调试扩展的屁股是一个巨大的痛苦:(

UPD: UPD:

As it appears, the problem is that only on one page I can't see errors: on the other pages where my script runs I can see console.errors(). 看来,问题是只在一个页面上我看不到错误:在我运行脚本的其他页面上,我可以看到console.errors()。

Rob W, sorry, but that doesn't answer my question. Rob W,对不起,但这不能回答我的问题。 I can use console.log(), but I can't see the output of console.error(), both from actual errors in script and my own calls of console.error(). 可以使用console.log(),但是我无法看到console.error()的输出,包括脚本中的实际错误和我自己的console.error()调用。 My script doesn't use the background scripts, only certain scripts for certain pages, as in the manifest.json below: 我的脚本不使用后台脚本,只使用某些页面的某些脚本,如下面的manifest.json所示:

{
    "manifest_version": 2,
    "permissions": ["tabs", "http://*/*", "https://*/*", "file:///*/*"],
    ...
    "content_scripts": [{ 
            // I can see my errors here...
        "matches": ["http://www.site.ru/*type=cheats*"],
        "js": ["cheats.js"]
    },{
            // and here...
        "matches": ["http://www.site.ru/bitrix/admin/iblock_element_edit.php*type=games*"],
        "js": ["idb.js","data.js","framework.js","script.js","wikipic.js"],
        "css":["styles.css"],
            "all_frames": true  
    },{
        "matches": ["http://www.site.ru/bitrix/admin/iblock_element_search.php*"],
        "js": ["search.js"]
    },{
            // >>>> But not here! <<<<
        "matches": ["http://www.site.ru/cheats/*"],
        "js": ["keys.js", "adhocparse.js", "resumeer.js", "ground.js"],
        "css": ["resumeer.css"]
    }]
}

UPD 2: I tried this code: UPD 2:我试过这段代码:

console.log(console, console.log, console.error);
console.error("Error one");
throw new Error("Error two");

I've got this output: 我有这个输出:

Console function log() { [native code] } function error() { [native code] }
Error one

So: console.error works, but all thrown errors (such as syntax errors) are somehow catched globally. 所以:console.error有效,但所有抛出的错误(例如语法错误)都以某种方式被全局捕获。 It is strange, because: 这很奇怪,因为:

  1. I don't have any catches in my extension; 我的扩展中没有任何捕获;
  2. Page itself still generates a lot of errors (but they occur before calling my extension code), and a lot of GET errors (unable to get a file, even after calling my extension code, but they seem to be uncatchable, I guess) 页面本身仍然会产生很多错误(但是它们在调用我的扩展代码之前就会出现),以及很多GET错误(即使在调用我的扩展代码之后也无法获取文件,但我认为它们似乎无法捕获)

So what can catch errors globally? 那么什么能在全球范围内发现错

It appears that this is not a Chrome extension issue, added tag javascript. 看来这不是Chrome扩展程序问题,添加了标记javascript。

On the site I wanted to write the extension for there was this code which caused such behavior: 在网站上我想编写扩展名,因为有这样的代码导致了这样的行为:

window.onerror
function stopError(){return true;}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM