devtools.inspectedWindow.tabId
The ID of the tab
that this instance of the devtools is attached to, represented as a number.
This can be sent to the extension's background page, so that background page can use the tabs
API to interact with the tab:
// devtools-panel.js
const scriptToAttach = "document.body.innerHTML = 'Hi from the devtools';";
attachContentScriptButton.addEventListener("click", () => {
browser.runtime.sendMessage({
tabId: browser.devtools.inspectedWindow.tabId,
script: scriptToAttach
});
});
// background.js
function handleMessage(request, sender, sendResponse) {
browser.tabs.executeScript(request.tabId, {
code: request.script
});
}
browser.runtime.onMessage.addListener(handleMessage);
Browser compatibility
Report problems with this compatibility data on GitHubwebextensions-desktop | webextensions-mobile | |||||
---|---|---|---|---|---|---|
tabId | ChromeFull supportYes | EdgeFull support79 | FirefoxFull support54 | OperaFull supportYes | SafariNo supportNo | Firefox for AndroidNo supportNo |
Legend
- Full support
- Full support
- No support
- No support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Acknowledgements
This API is based on Chromium's chrome.devtools
API.
Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.