4

I've encountered an issue that drives me completely nuts.

My chrome extension doesn't report any errors to Developer Tools console. 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.

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:

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().

Rob W, sorry, but that doesn't answer my question. 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(). My script doesn't use the background scripts, only certain scripts for certain pages, as in the manifest.json below:

{
    "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:

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. 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)

So what can catch errors globally?

It appears that this is not a Chrome extension issue, added tag javascript.

gvlasov
  • 18,638
  • 21
  • 74
  • 110
  • Welcome to Stack Overflow. This question has already been asked earlier, you can find the Q&A at this post: [Where to read console messages from background.js in a Chrome extension?](http://stackoverflow.com/questions/10257301/where-to-read-console-messages-from-background-js-in-a-chrome-extension). – Rob W Jul 21 '12 at 08:57
  • What if you sandwich an error call between two log calls like `log('foo'); error('bar'); log('baz');`? Do you see both logs and not the error? Or do you only see the first log? It's possible that `console.error` has been rewritten or that some kind of `try`/`catch` operation is catching your error, preventing it from being displayed. – apsillers Jul 21 '12 at 21:10
  • Then only the first log is displayed, and nothing after. It apears that it has nothing to do with console.error, see update 2. – gvlasov Jul 21 '12 at 21:40

1 Answers1

0

On the site I wanted to write the extension for there was this code which caused such behavior:

window.onerror
function stopError(){return true;}
gvlasov
  • 18,638
  • 21
  • 74
  • 110