Convert "Create a DevTools extension" to sample-based#3616
Conversation
Update and reorganize documentation for the Custom DevTools tool sample and related getting-started content. Changes include: - Bumped ms.date to 2026-04-20 in multiple extension docs. - Reworked microsoft-edge/extensions/developer-guide/devtools-extension.md: clarified the relationship between the guide and samples, reorganized file overview (manifest, panel, devtools.html, devtools.js, background.js, content_script.js, icon.png), added sibling links to sample and code, refined wording and added TODO notes. - Simplified microsoft-edge/extensions/getting-started/index.md intro and updated date. - Updated microsoft-edge/extensions/samples/custom-devtools-tool-code.md: revised description, date, sibling markers, clarified devtools.html wording and file list entries. - Updated microsoft-edge/extensions/samples/custom-devtools-tool.md: updated date, sibling links, added GitHub repo links and rearranged 'See also' / Tools references. Overall this commit improves clarity, linking between guide/sample/code, and consistency of file descriptions.
PoliCheck Scan ReportThe following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 and severity-2 issues. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans. ✅ No issues foundMore information about PoliCheckInformation: PoliCheck | Severity Guidance | Term |
|
Learn Build status updates of commit bb1eee7: ✅ Validation status: passed
This comment lists only the first 25 files in the pull request. |
|
|
||
| 1. In DevTools, in the **Activity Bar**, select the **Console** () tool. | ||
|
|
||
| The message "Connected!" is displayed in the **Console** tool.<!-- todo: true? how can we view that message? --> |
There was a problem hiding this comment.
how view message?
There was a problem hiding this comment.
See MicrosoftEdge/Demos#106 (comment)
There's no "Connected" message, so let's remove this line.
|
|
||
| 1. Navigate to the `/Demos-main/devtools-extension/` folder, such as `C:\Users\localAccount\GitHub\Demos-main\devtools-extension\`, and then click the **Select Folder** button.<!-- actually used forked cloned /Demos/ dir, a working branch, which has latest version of sample --> | ||
|
|
||
| A dialog opens, asking whether to open the repo in the parent folder.<!-- todo: does the dialog open even if when working from the downloaded zip? doesn't this dialog only appear when working off of the cloned repo? --> |
There was a problem hiding this comment.
does the dialog open even if when working from the downloaded zip?
doesn't this dialog only appear when working off of the cloned repo?
There was a problem hiding this comment.
probably not wwhen .zipdl'd.
There was a problem hiding this comment.
Correct, when downloading the zip, the git repository metadata does not exist and VS Code will not display a dialog. So let's remove this line.
| | `devtools.html` | A non-rendered HTML file that's run when DevTools is opened, to load the extension's JavaScript files. | | ||
| | `devtools.js` | Main logic for the custom DevTools page. | | ||
| | `service-worker.js` | A service worker that sets up event listeners for communications between the inspected page and DevTools. | | ||
| | `content_script.js` | Code which the extension injects in the inspected webpage. Prints a message<!-- todo: what message? --> to the console when the script is injected in the page. Adds a click event listener to the page that will send a message with mouse-click position in the inspected page. | |
There was a problem hiding this comment.
Nothing happens WHEN the script is injected.
when page is clicked, the message appears in console: "Received response"
response => { console.log("Received response", response); }
and also in custom tool, the coordinates of click are printed.
|
|
||
| 1. Click the **Say Hello to The Inspected Page!** button. | ||
| This file does the following: | ||
| * Prints a message<!-- todo: what message? --> to the DevTools **Console** when the page is clicked. |
There was a problem hiding this comment.
Prints what message?
There was a problem hiding this comment.
There was a problem hiding this comment.
Remove this step. Nothing is printed.
| | `devtools.html` | A non-rendered HTML file that's run when DevTools is opened, to load the extension's JavaScript files. | | ||
| | `devtools.js` | Main logic for the custom DevTools page. | | ||
| | `service-worker.js` | A service worker that sets up event listeners for communications between the inspected page and DevTools. | | ||
| | `content_script.js` | Code which the extension injects in the inspected webpage. Prints a message<!-- todo: what message? --> to the console when the script is injected in the page. Adds a click event listener to the page that will send a message with mouse-click position in the inspected page. | |
There was a problem hiding this comment.
| | `content_script.js` | Code which the extension injects in the inspected webpage. Prints a message<!-- todo: what message? --> to the console when the script is injected in the page. Adds a click event listener to the page that will send a message with mouse-click position in the inspected page. | | |
| | `content_script.js` | Code which the extension injects in the inspected webpage. Adds a click event listener to the page that will send a message with the mouse-click position in the inspected page. Sends a message to ... | |
sends a message, and devtools.js is listenging for that message as foolows:
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
// Messages from content scripts should have sender.tab set.
if (sender.tab && request.click == true) {
console.log('I am here!');
if (youClickedOn) {
youClickedOn.innerHTML = `(${request.xPosition}, ${request.yPosition})`;
}
sendResponse({
xPosition: request.xPosition,
yPosition: request.yPosition
});
}
});
There was a problem hiding this comment.
| | `content_script.js` | Code which the extension injects in the inspected webpage. Prints a message<!-- todo: what message? --> to the console when the script is injected in the page. Adds a click event listener to the page that will send a message with mouse-click position in the inspected page. | | |
| | `content_script.js` | Code which the extension injects in the inspected webpage. Adds a click event listener to the page that will send a message with the mouse-click position. `devtools.js` listens to this message and displays the position in the custom panel. | |
|
|
||
| 1. In DevTools, in the **Activity Bar**, select the **Console** () tool. | ||
|
|
||
| The message "Connected!" is displayed in the **Console** tool.<!-- todo: true? how can we view that message? --> |
There was a problem hiding this comment.
See MicrosoftEdge/Demos#106 (comment)
There's no "Connected" message, so let's remove this line.
|
|
||
| 1. Navigate to the `/Demos-main/devtools-extension/` folder, such as `C:\Users\localAccount\GitHub\Demos-main\devtools-extension\`, and then click the **Select Folder** button.<!-- actually used forked cloned /Demos/ dir, a working branch, which has latest version of sample --> | ||
|
|
||
| A dialog opens, asking whether to open the repo in the parent folder.<!-- todo: does the dialog open even if when working from the downloaded zip? doesn't this dialog only appear when working off of the cloned repo? --> |
There was a problem hiding this comment.
Correct, when downloading the zip, the git repository metadata does not exist and VS Code will not display a dialog. So let's remove this line.
| | `panel.html` | Webpage to display in the custom panel in DevTools. | | ||
| | `devtools.html` | A non-rendered HTML file that's run when DevTools is opened, to load the extension's JavaScript files. | | ||
| | `devtools.js` | Main logic for the custom DevTools page. | | ||
| | `service-worker.js` | A service worker that sets up event listeners for communications between the inspected page and DevTools. | |
There was a problem hiding this comment.
Remove this, see MicrosoftEdge/Demos#106 (comment)
| | `devtools.html` | A non-rendered HTML file that's run when DevTools is opened, to load the extension's JavaScript files. | | ||
| | `devtools.js` | Main logic for the custom DevTools page. | | ||
| | `service-worker.js` | A service worker that sets up event listeners for communications between the inspected page and DevTools. | | ||
| | `content_script.js` | Code which the extension injects in the inspected webpage. Prints a message<!-- todo: what message? --> to the console when the script is injected in the page. Adds a click event listener to the page that will send a message with mouse-click position in the inspected page. | |
There was a problem hiding this comment.
| | `content_script.js` | Code which the extension injects in the inspected webpage. Prints a message<!-- todo: what message? --> to the console when the script is injected in the page. Adds a click event listener to the page that will send a message with mouse-click position in the inspected page. | | |
| | `content_script.js` | Code which the extension injects in the inspected webpage. Adds a click event listener to the page that will send a message with the mouse-click position. `devtools.js` listens to this message and displays the position in the custom panel. | |
| * `content_script.js` is a _content script_, which means that it runs in the context of the inspected webpage. In the same way that other scripts are loaded by the webpage, a content script has access to the DOM and can change it. | ||
|
|
||
| 1. Click anywhere in the inspected page. | ||
| * `service-worker.js` is a _background service worker_. It runs in a separate thread and has access to extension APIs. |
There was a problem hiding this comment.
We should remove since the service worker doesn't play any role in this extension. See MicrosoftEdge/Demos#106 (comment)
|
|
||
| **background.js:** | ||
| <!-- ====================================================================== --> | ||
| ## `service-worker.js` |
There was a problem hiding this comment.
See MicrosoftEdge/Demos#106 (comment)
This file doesn't seem to actually be needed. So we might just want to remove this whole section.
|
|
||
| 1. Click the **Say Hello to The Inspected Page!** button. | ||
| This file does the following: | ||
| * Prints a message<!-- todo: what message? --> to the DevTools **Console** when the page is clicked. |
There was a problem hiding this comment.
Remove this step. Nothing is printed.
| * Adds a click event listener to the inspected webpage, that sends a message containing the mouse-click position, by calling `chrome.runtime.sendMessage`. | ||
| * Listens for the page click event via an event listener. | ||
| * Adds a click event listener to the inspected webpage; clicking the page sends an event, caught by the event listener, which then sends a message to the WebView2 Runtime. |
There was a problem hiding this comment.
| * Adds a click event listener to the inspected webpage, that sends a message containing the mouse-click position, by calling `chrome.runtime.sendMessage`. | |
| * Listens for the page click event via an event listener. | |
| * Adds a click event listener to the inspected webpage; clicking the page sends an event, caught by the event listener, which then sends a message to the WebView2 Runtime. | |
| * Adds a click event listener to the inspected webpage, that sends a message containing the mouse-click position, by calling `chrome.runtime.sendMessage`. | |
| * Listens for the page click event via an event listener. |
That second bullet point was wrong, it's partly a duplicate of the first point, and mentions WebView2, which is wrong in this context.
|
Learn Build status updates of commit 3b5abe4: ❌ Validation status: errorsPlease follow instructions here which may help to resolve issue.
For more details, please refer to the build report. Note: Your PR may contain errors or warnings or suggestions unrelated to the files you changed. This happens when external dependencies like GitHub alias, Microsoft alias, cross repo links are updated. Please use these instructions to resolve them. |
| The DevTools page, inspected page, and content script fit together in an extension: | ||
|
|
||
| 1. Click anywhere in the inspected page. | ||
| <!-- todo: omit SW --> |
There was a problem hiding this comment.
omit Service Worker from diagram
direct png link:
https://review.learn.microsoft.com/en-us/microsoft-edge/extensions/developer-guide/devtools-extension-images/architecture.png?branch=pr-en-us-3616
@captainbrosset how to proceed?

Related PRs:
Overview of PR:
Rendered articles for review:
1a. Get started developing an extension
/extensions/getting-started/index.mdarchitecture.md.1b. Extension concepts and architecture
/extensions/getting-started/architecture.mdindex.md.2a. Samples for Microsoft Edge extensions > MicrosoftEdge/Demos repo
/extensions/samples.md3a. Develop an extension for the Microsoft Edge sidebar
/extensions/developer-guide/sidebar.md4a. Add a custom tool in Microsoft Edge DevTools
/extensions/developer-guide/devtools-extension.md4b. Sample: Custom DevTools tool
/extensions/developer-guide/devtools-extension-sample.mdIncidental:
5a. Many files
TOC
/toc.ymlOverview of Microsoft Edge extensions
/extensions/index.mdSites for extensions for various browsers
to:
Creating an extension for various browsers
AB#55086309