0

I am new to Javascript and am trying to make a Chrome extension. However, the console log isn't printing anything to the console I opened using f12. The code executes other functions, like opening a tab, but prints nothing. I've searched through a lot of questions about the same problem but none of the causes seemed to be mine. Thanks.

chrome.browserAction.onClicked.addListener (function (tab)
{
    var teste = new Object();
    chrome.tabs.create  (teste);
    alert(123);
    chrome.tabs.executeScript( {file:"viewer.js"});
});
BlitZ
  • 12,038
  • 3
  • 49
  • 68
rvcam
  • 157
  • 5
  • 15
  • And if you replace console.log with alert(123), does it come up? – dfsq Feb 15 '14 at 08:31
  • where is you code..? also check `if (window.console) { }` – Deepak Ingole Feb 15 '14 at 08:34
  • If I use alert(123), it comes up. Also, added the code – rvcam Feb 15 '14 at 08:44
  • 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 Feb 16 '14 at 15:38

2 Answers2

0

If you're app is running from the pop-up, you have direct access to the background page via the chrome.extension.getBackgroundPage() method.

Therefore, you can log to the console like this:

chrome.extension.getBackgroundPage().console.log('hello');
krisk
  • 6,957
  • 1
  • 18
  • 30
  • Just to eliminate the obvious, but did you inspect the proper console? Specifically, right click on the extension icon --> inspect pop up? – krisk Feb 15 '14 at 08:44
  • I am not using a pop up (it's an event page), so I can't use inspect pop up. I'm using the f12 console. – rvcam Feb 15 '14 at 08:51
  • Perhaps consider Message Parsing? (http://developer.chrome.com/extensions/messaging.html) Take a look at this answer: http://stackoverflow.com/questions/2998775/chrome-extension-message-passing/2999305?noredirect=1#2999305 – krisk Feb 15 '14 at 08:58
  • But it is on the background script that I can't write on console – rvcam Feb 15 '14 at 11:09
  • @Hrodruck http://stackoverflow.com/questions/9970648/about-debugging-chrome-extension – levi Feb 15 '14 at 15:46
  • I can see the background logs, but not the content script ones. I'ts not a fault in my program since I downloaded a sample program and still couldn't see the content script logs – rvcam Feb 15 '14 at 18:00
0

From the extion list page, you should be able to inspect background page. (There will be a link there)

PatAtCP
  • 577
  • 3
  • 10