Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to find code and console to debug background.js in Chrome extension

how can I debug the code that I have in my background.js which contain some of my browser action.

the code is running on the load of the tab to validate the URL

chrome.tabs.onUpdated.addListener(checkForValidUrl); 

but when I inspect the pop up and try to debug into my code I can not find background.js in my files.

how can I debug this file ?

like image 610
Ali Esmailian Avatar asked Aug 09 '13 11:08

Ali Esmailian


People also ask

How do I debug a Chrome background?

Just scroll to the extension you want to debug and click on the background page link to inspect it. Tip: To reload the extension, you can press F5 inside the developer tools window. You can put breakpoints in the initialization code before reloading.

How can I see the source code of Chrome extensions?

After the extension is added to your browser, open an extension's page on the Chrome Web Store, such as the Markdown Preview extension page. When the page loads, click on the CRX icon in the extensions bar in Chrome and select “View source.”


1 Answers

You can debug your extension's background.js in the development environment (debugger) from the Chrome Extension page at chrome://extensions:

It has a link to do that in each extension, often called "generated background page.html", (because Chrome generate a html page to contain your js).

If you're using Event Pages (background page with persistent:false in your manifest code), perhaps you should like to turn into persistent:true only for debug purpose.

The Event Page (i.e. persistent:false) unloads after few secondos of inactivity, and closes its debug window. persistent:true changes this, the page doesn't unload. It's better for debug, but turn into persistent:false when you get the debug done, because it's more efficient.

like image 174
Alejandro Silvestri Avatar answered Sep 19 '22 01:09

Alejandro Silvestri