Skip to content

Convert "Create a DevTools extension" to sample-based#3616

Open
mikehoffms wants to merge 47 commits into
mainfrom
user/mikehoffms/devtools-extension
Open

Convert "Create a DevTools extension" to sample-based#3616
mikehoffms wants to merge 47 commits into
mainfrom
user/mikehoffms/devtools-extension

Conversation

@mikehoffms
Copy link
Copy Markdown
Collaborator

@mikehoffms mikehoffms commented Oct 24, 2025

Related PRs:

Overview of PR:

  1. Get started developing an extension
    • New short article (basic extension; not sidebar, not DevTools tool).
    • Leverages Sample: Picture viewer pop-up webpage.
  2. Samples for Microsoft Edge extensions
    • Linked to "GoogleChrome / chrome-extensions-samples" repo.
  3. Develop an extension for the Microsoft Edge sidebar
    • Updated per upstream.
      • Added sync comments, to facilitate maintenance.
    • Clearly linked to 5 Google samples.
  4. Create a DevTools extension, adding a custom tool tab and panel - broke out as 2 articles:
    • Add a custom tool in Microsoft Edge DevTools
    • Sample: Custom DevTools tool
      • Removed wording about creating that sample (as phase 3 & phase 4, two different versions of the sample).
  5. Trimmed leading spaces in lists, globally in repo.

Rendered articles for review:


Incidental:

AB#55086309

@mikehoffms mikehoffms changed the title Standardize "Sample: Custom DevTools tool tab and panel" Break into 3 "Create a DevTools extension, adding a custom tool tab and panel" Oct 28, 2025
@mikehoffms mikehoffms changed the title Break into 3 "Create a DevTools extension, adding a custom tool tab and panel" Break into 3 "Create a DevTools extension, adding custom tool" Oct 28, 2025
@mikehoffms mikehoffms changed the title Break into 3 "Create a DevTools extension, adding custom tool" Break out "Sample: Custom DevTools tool" from "Create a DevTools extension" Oct 29, 2025
@mikehoffms mikehoffms changed the title Break out "Sample: Custom DevTools tool" from "Create a DevTools extension" Break out "Custom DevTools sample" from "Create DevTools extension" Oct 29, 2025
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.
Comment thread microsoft-edge/extensions/developer-guide/devtools-extension.md
Comment thread microsoft-edge/extensions/developer-guide/sidebar.md Outdated
Comment thread microsoft-edge/extensions/developer-guide/sidebar.md Outdated
Comment thread microsoft-edge/extensions/developer-guide/sidebar.md Outdated
Comment thread microsoft-edge/extensions/developer-guide/sidebar.md Outdated
Comment thread microsoft-edge/extensions/samples/custom-devtools-tool-code.md Outdated
Comment thread microsoft-edge/extensions/samples/custom-devtools-tool-code.md Outdated
Comment thread microsoft-edge/extensions/samples/custom-devtools-tool-code.md Outdated
Comment thread microsoft-edge/extensions/samples/custom-devtools-tool-code.md Outdated
Comment thread microsoft-edge/extensions/samples/custom-devtools-tool-code.md Outdated
@learn-build-service-prod
Copy link
Copy Markdown
Contributor

Learn Build status updates of commit ee7b11d:

✅ Validation status: passed

File Status Preview URL Details
CODE_OF_CONDUCT.md ✅Succeeded
CONTRIBUTING.md ✅Succeeded
microsoft-edge/accessibility/build/index.md ✅Succeeded View
microsoft-edge/accessibility/design.md ✅Succeeded View
microsoft-edge/accessibility/index.md ✅Succeeded View
microsoft-edge/accessibility/test.md ✅Succeeded View
microsoft-edge/develop-web-microsoft-edge.md ✅Succeeded View
microsoft-edge/developer/index.yml ✅Succeeded View
microsoft-edge/devtools/network-request-blocking/network-request-blocking-tool.md ✅Succeeded View
microsoft-edge/devtools/overview.md ✅Succeeded View
microsoft-edge/devtools/performance-monitor/performance-monitor-tool.md ✅Succeeded View
microsoft-edge/devtools/performance/index.md ✅Succeeded View
microsoft-edge/devtools/performance/reference.md ✅Succeeded View
microsoft-edge/devtools/progressive-web-apps/index.md ✅Succeeded View
microsoft-edge/devtools/quick-source/quick-source-tool.md ✅Succeeded View
microsoft-edge/devtools/recorder/index.md ✅Succeeded View
microsoft-edge/devtools/remote-debugging/index.md ✅Succeeded View
microsoft-edge/devtools/remote-debugging/surface-duo-emulator.md ✅Succeeded View
microsoft-edge/devtools/remote-debugging/webviews.md ✅Succeeded View
microsoft-edge/devtools/remote-debugging/windows.md ✅Succeeded View
microsoft-edge/devtools/rendering-tools/index.md ✅Succeeded View
microsoft-edge/devtools/rendering-tools/js-runtime.md ✅Succeeded View
microsoft-edge/devtools/resources/index.md ✅Succeeded View
microsoft-edge/devtools/samples/index.md ✅Succeeded View
microsoft-edge/devtools/search/search-tool.md ✅Succeeded View

This comment lists only the first 25 files in the pull request.
For more details, please refer to the build report.

Comment thread microsoft-edge/extensions/developer-guide/devtools-extension.md Outdated
Comment thread microsoft-edge/extensions/developer-guide/devtools-extension.md Outdated
Comment thread microsoft-edge/extensions/developer-guide/devtools-extension.md Outdated
Comment thread microsoft-edge/extensions/developer-guide/devtools-extension.md Outdated
Comment thread microsoft-edge/extensions/developer-guide/devtools-extension.md Outdated
Comment thread microsoft-edge/extensions/developer-guide/devtools-extension.md Outdated
Comment thread microsoft-edge/extensions/developer-guide/devtools-extension.md Outdated
Comment thread microsoft-edge/extensions/developer-guide/devtools-extension.md Outdated
Comment thread microsoft-edge/extensions/developer-guide/devtools-extension.md Outdated
Comment thread microsoft-edge/extensions/developer-guide/devtools-extension-sample.md Outdated
@learn-build-service-prod
Copy link
Copy Markdown
Contributor

PoliCheck Scan Report

The 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 found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

@learn-build-service-prod
Copy link
Copy Markdown
Contributor

Learn Build status updates of commit bb1eee7:

✅ Validation status: passed

File Status Preview URL Details
CODE_OF_CONDUCT.md ✅Succeeded
CONTRIBUTING.md ✅Succeeded
microsoft-edge/accessibility/build/index.md ✅Succeeded View
microsoft-edge/accessibility/design.md ✅Succeeded View
microsoft-edge/accessibility/index.md ✅Succeeded View
microsoft-edge/accessibility/test.md ✅Succeeded View
microsoft-edge/develop-web-microsoft-edge.md ✅Succeeded View
microsoft-edge/developer/index.yml ✅Succeeded View
microsoft-edge/devtools/network-request-blocking/network-request-blocking-tool.md ✅Succeeded View
microsoft-edge/devtools/overview.md ✅Succeeded View
microsoft-edge/devtools/performance-monitor/performance-monitor-tool.md ✅Succeeded View
microsoft-edge/devtools/performance/index.md ✅Succeeded View
microsoft-edge/devtools/performance/reference.md ✅Succeeded View
microsoft-edge/devtools/progressive-web-apps/index.md ✅Succeeded View
microsoft-edge/devtools/quick-source/quick-source-tool.md ✅Succeeded View
microsoft-edge/devtools/recorder/index.md ✅Succeeded View
microsoft-edge/devtools/remote-debugging/index.md ✅Succeeded View
microsoft-edge/devtools/remote-debugging/surface-duo-emulator.md ✅Succeeded View
microsoft-edge/devtools/remote-debugging/webviews.md ✅Succeeded View
microsoft-edge/devtools/remote-debugging/windows.md ✅Succeeded View
microsoft-edge/devtools/rendering-tools/index.md ✅Succeeded View
microsoft-edge/devtools/rendering-tools/js-runtime.md ✅Succeeded View
microsoft-edge/devtools/resources/index.md ✅Succeeded View
microsoft-edge/devtools/samples/index.md ✅Succeeded View
microsoft-edge/devtools/search/search-tool.md ✅Succeeded View

This comment lists only the first 25 files in the pull request.
For more details, please refer to the build report.


1. In DevTools, in the **Activity Bar**, select the **Console** (![Console icon](./devtools-extension-sample-images/console-icon.png)) tool.

The message "Connected!" is displayed in the **Console** tool.<!-- todo: true? how can we view that message? -->
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how view message?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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? -->
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not wwhen .zipdl'd.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. |
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What message?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prints what message?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seq:

  1. msg is sent from content_script.js, received by devtools.js.
  2. displays the coordinates in the custome tool in devtools, in panel.html
  3. reply from devtools.js is received by content_script.js.
  4. prints to console: console.log("Received response", response); to the console
image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. |
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| `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
        });
    }
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| `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** (![Console icon](./devtools-extension-sample-images/console-icon.png)) tool.

The message "Connected!" is displayed in the **Console** tool.<!-- todo: true? how can we view that message? -->
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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? -->
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

| `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. |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| `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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this step. Nothing is printed.

Comment on lines +407 to +409
* 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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 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-service-prod
Copy link
Copy Markdown
Contributor

Learn Build status updates of commit 3b5abe4:

❌ Validation status: errors

Please follow instructions here which may help to resolve issue.

File Status Preview URL Details
❌Error Details

  • [Error: CannotMergeCommit] Cannot merge commit 3b5abe4b1ca8bc5acda449a5f813e293cbec47fb in branch user/mikehoffms/devtools-extension of repository https://github.com/MicrosoftDocs/edge-developer into branch main (commit 224ee66932072310555912e011ace44fcf84b5ce). Please follow this documentation: https://help.github.com/articles/resolving-a-merge-conflict-using-the-command-line/ to use git.exe to resolve you content conflicts locally and then push to remote.

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.
![Diagram showing the anatomy of a DevTools extension](./devtools-extension-images/architecture.png)<!-- todo: omit SW -->
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cat: extensions Extensions-related content.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants