Debugging background scripts
Background scripts enable an extension to maintain a long-term state or perform long-term operations, independently of any web page or browser window. These scripts remain loaded for the lifetime of the extension. Background scripts are loaded inside an invisible background page: by default, this is an empty HTML document, but you can specify a custom page and define it as the background page using the
To debug background scripts, use the Toolbox Debugger in the split console view so you can view the Console below Debugger.
To get started, open your background script in Sources.
As you run your extension, the Console displays logged output, including calls to
console.log() made by the extension's background scripts and any errors the browser raises as it executes these scripts. Note that the console shows all errors raised by the browser, not just errors related to your extension's code.
For example, the notify-link-clicks-i18n example extension logs a message from its background script when it receives a message from one of its content scripts.
Using the Console command line, you can access and modify the objects created by your background scripts. For example, you can call the
In the Debugger you can set breakpoints, step through code, modify the extension's state, and do everything else you'd expect to be able to do in a debugger.
For more information about using the debugger, see the Debugger guide.