0

I'm trying to build my first Chrome extension but I found problems with debugging.

I'm able to console.log() but in the Developer Tools console (I'm working on the background.js; no UI) there's no report about syntax errors.

Is that normal? Or it depends on some settings of the page I'm creating the extension for? (www.google.com)

I've read maybe there could be a window.onerror set somewhere but I'm not able to find it. I tried a window.onerror = null;
at the beginning of the background.js but nothing has changed.

What would you do to get the errors back?

UPDATE (Adding code)

This is the manifest.json:

{
  "name": "Name",
  "description": "Description",
  "version": "0.1",
  "manifest_version": 2,
  "background": {
      "persistent": false,
      "scripts": ["js/background.js"]
  },
  "permissions" : [
      "tabs",
      "*://www.google.com/*",
      "*://www.google.de/*"
    ],
  "commands": {
    "changeSearch": {
      "suggested_key": { 
            "default": "Ctrl+Shift+A",
            "mac": "Command+Shift+A"
        },
      "description": "Change."
    }  
  }
}

The background.js start like this:

console.log("Start");
chrome.commands.onCommand.addListener(function(command) {
    consTYPOTYPOTYPOTYPOTYPOTYPOle.log("catched");
    ...

I just discovered that errors are thrown if the TYPO is otuside of function(command) code, if I have TYPOs on the 1st or 2nd line. The 3rd line is totally silent. No error. It just doesn't work.

That's weird to me!

Kamafeather
  • 8,663
  • 14
  • 69
  • 99
  • possible duplicate of [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 Mar 06 '14 at 14:32
  • @RobW I've already seen that. Is not the same problem. I'm able to debug but there is something that is stopping the parser from reporting errors in the console. – Kamafeather Mar 06 '14 at 15:07
  • That is not possible. Are you sure that there is an actual error in the [background page](https://developer.chrome.com/extensions/background_pages) and that you are looking at the console of your extension? [Content script](https://developer.chrome.com/extensions/content_scripts) messages appear in the console of the web page, and errors in the [extension popup](https://developer.chrome.com/extensions/browserAction#popup) appear in the console of the popup. – Rob W Mar 06 '14 at 15:09
  • I have no popup or content script. My extension just wait for a key combination and execute some code. I set an error on purpose; I load the extension; load the page; click on "background page" link near to "Inspect active views" (as in your answer). I'm able to see all the `console.log`s I throw from my extension's *background.js* but I cannot see errors. I tried to remove one bracket and it reports an `Uncaught SyntaxError`; but if I use a function or variable that don't exist nothing is reported. – Kamafeather Mar 06 '14 at 15:45
  • Then you need to show your code. – Rob W Mar 06 '14 at 16:26
  • @RobW added some code, and just discovered the problem is happening just inside the listener function! – Kamafeather Mar 06 '14 at 17:03
  • What version of Chrome are you using? I cannot reproduce it in 31.0.1650.63 nor 35.0.1863.0. – Rob W Mar 06 '14 at 17:12
  • Version 35.0.1866.0 (254322) - It's Chromium. – Kamafeather Mar 06 '14 at 17:18
  • Can't reproduce with 35.0.1873.0 (r255009 Canary on Windows) either. Probably a temporary issue that got resolved. (the tests in my previous comments are on Linux) – Rob W Mar 06 '14 at 17:34
  • I solved! Thinking about a conflict with some other extension I tried to disable all the others and the errors came back to console! So I re-enabled them progressively and testing each time...... finishing re-activating them all and having the errors in the console still working! Some kind of bug I guess :| – Kamafeather Mar 06 '14 at 17:47
  • 2
    It is possible that some other extension has mapped the same shortcut. By disabling them all and re-enabling them one after the other you have mapped your extension as the first to the shortcut and hence made it working ;-) – Draško Kokić Mar 08 '14 at 09:59
  • I didn't think about that!! :O .... Would be interesting (and useful) to be have a way to detect these kind of conflicts – Kamafeather Mar 08 '14 at 19:01

1 Answers1

0

The problem was a conflicting extension that was overriding mine.

Trying to disable all extensions and then re-enabling them, starting from mine, solved the problem.

Probably I made it to have higher priority respect to the conflicting extension (that has been enabled after).

Kamafeather
  • 8,663
  • 14
  • 69
  • 99