Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

console.log not showing output in Chrome browser

I am using Chrome browser Version 52.0.2743.116 (64-bit) on Mac OSX 10.11.6.

I have a chrome extension with a background.js where I have a console.log statement for debugging purposes. However, I am unable to see the output in the Chrome browser console. Alert works fine but console.log outputs nothing.

alert("CSS code: "+css);
console.log("CSS code:"+css);

I have checked to make sure "All" messages are selected, the context is set to "top", etc. When the page loads, I see other console.log messages (not from my extension), the alert window pop up but nothing printed to the console.

How do I see console.log output?

EDIT: Adding the function code where the alert and console.log statements appear.

function doSomething(tab) {
    var tabUrl = tab.url;

        if (tabUrl && tabUrl.indexOf("my-site.com") != -1) {

            var css = "";

            if (hideAds == true) {
                css += ".adsBanner {display: none !important;} .promo {display: none !important;} ";
            }

            alert("CSS code: "+css);
            console.log("CSS code:"+css);

            chrome.tabs.insertCSS(tab.id, {
                code: css
            });

        }       
}

EDIT 2: In response to the comment that this is a duplicate of this question, I want to print console.log statements from the background file, I don't have a popup.html file. The other question has solutions to execute console.log on the background page called from the popup page.

like image 784
zeeshan Avatar asked Aug 11 '16 11:08

zeeshan


People also ask

How do I check output of console log?

Steps to Open the Console Log in Google Chrome By default, the Inspect will open the "Elements" tab in the Developer Tools. Click on the "Console" tab which is to the right of "Elements". Now you can see the Console and any output that has been written to the Console log.

How do I enable console debugging in Chrome?

Click the Console tab. Press Control + [ or Command + [ (Mac) until the Console is in focus. Open the Command Menu, start typing Console , select the Show Console Panel command, and then press Enter .


1 Answers

This has been previously answered here. It seems the background.js has its own console window that needs to be watched (launched from the extension's inpsect view link under chrome://extensions).

like image 154
zeeshan Avatar answered Oct 15 '22 02:10

zeeshan