chrome.devtools.panels (original) (raw)

Description

Use the chrome.devtools.panels API to integrate your extension into Developer Tools window UI: create your own panels, access existing panels, and add sidebars.

Each extension panel and sidebar is displayed as a separate HTML page. All extension pages displayed in the Developer Tools window have access to all parts of the chrome.devtools API, as well as all other extension APIs.

You can use the devtools.panels.setOpenResourceHandler method to install a callback function that handles user requests to open a resource (typically, a click a resource link in the Developer Tools window). At most one of the installed handlers gets called; users can specify (using the Developer Tools Settings dialog) either the default behavior or an extension to handle resource open requests. If an extension calls setOpenResourceHandler() multiple times, only the last handler is retained.

See DevTools APIs summary for general introduction to using Developer Tools APIs.

Manifest

The following keys must be declared in the manifest to use this API.

"devtools_page"

Example

The following code adds a panel contained in Panel.html, represented by FontPicker.png on the Developer Tools toolbar and labeled as Font Picker:

chrome.devtools.panels.create("Font Picker",
                              "FontPicker.png",
                              "Panel.html",
                              function(panel) { ... });

The following code adds a sidebar pane contained in Sidebar.html and titled Font Properties to the Elements panel, then sets its height to 8ex:

chrome.devtools.panels.elements.createSidebarPane("Font Properties",
  function(sidebar) {
    sidebar.setPage("Sidebar.html");
    sidebar.setHeight("8ex");
  }
);

The screenshot illustrates the effect this example would have on Developer Tools window:

Extension icon panel on DevTools toolbar

Extension icon panel on DevTools toolbar.

To try this API, install the devtools panels API example from the chrome-extension-samplesrepository.

Types

Button

A button created by the extension.

Properties

ElementsPanel

Represents the Elements panel.

Properties

ExtensionPanel

Represents a panel created by an extension.

Properties

A sidebar created by the extension.

Properties

SourcesPanel

Represents the Sources panel.

Properties

Theme

Theme used by DevTools.

Enum

"default"
Default DevTools theme. This is always the light theme.

"dark"
Dark theme.

Properties

Type

Type

themeName

The name of the color theme set in user's DevTools settings. Possible values: default (the default) and dark.

Methods

create()

chrome.devtools.panels.create(
  title: string,
  iconPath: string,
  pagePath: string,
  callback?: function,
): void

Creates an extension panel.

Parameters

openResource()

chrome.devtools.panels.openResource(
  url: string,
  lineNumber: number,
  columnNumber?: number,
  callback?: function,
): void

Requests DevTools to open a URL in a Developer Tools panel.

Parameters

setOpenResourceHandler()

chrome.devtools.panels.setOpenResourceHandler(
  callback?: function,
): void

Specifies the function to be called when the user clicks a resource link in the Developer Tools window. To unset the handler, either call the method with no parameters or pass null as the parameter.

Parameters

setThemeChangeHandler()

chrome.devtools.panels.setThemeChangeHandler(
  callback?: function,
): void

Specifies the function to be called when the current theme changes in DevTools. To unset the handler, either call the method with no parameters or pass null as the parameter.

Parameters