-
Notifications
You must be signed in to change notification settings - Fork 207
Delete per-phase dirs from /devtools-extension/ #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c08796e
a3e3d5d
0635d81
47168ca
5d3704c
5dd49a8
378d047
1a67f59
d141b56
ee741d1
862f1d4
dd40c51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,9 @@ | ||
| # Create your own DevTools extension | ||
| # Custom DevTools tool | ||
|
|
||
| This is the source code for the tutorial to create a Microsoft Edge extension that extends DevTools. See [Create a DevTools extension, adding a custom tool tab and panel](https://learn.microsoft.com/microsoft-edge/extensions/developer-guide/devtools-extension). | ||
| This Microsoft Edge extension sample adds a **Custom** tool in Microsoft Edge DevTools, including a tab in the **Activity Bar**, and a panel below the tab. | ||
|
|
||
| * The **Custom** DevTools tool calls the DevTools API to display memory information. | ||
|
|
||
| * The webpage under inspection, and the **Custom** DevTools tool, send messages to each other. | ||
|
|
||
| For instructions, see [Sample: Custom DevTools tool](https://learn.microsoft.com/microsoft-edge/extensions/samples/custom-devtools-tool). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| let availableMemoryCapacity; | ||
| let totalMemoryCapacity; | ||
| let youClickedOn; | ||
|
|
||
| chrome.devtools.panels.create("Custom", "icon.png", "panel.html", panel => { | ||
| // Code invoked on panel creation. | ||
| panel.onShown.addListener( (extPanelWindow) => { | ||
| // Memory API. | ||
| availableMemoryCapacity = extPanelWindow.document.querySelector('#availableMemoryCapacity'); | ||
| totalMemoryCapacity = extPanelWindow.document.querySelector('#totalMemoryCapacity'); | ||
| // 2-way message sending. | ||
| let sayHello = extPanelWindow.document.querySelector('#sayHello'); | ||
| youClickedOn = extPanelWindow.document.querySelector('#youClickedOn'); | ||
| sayHello.addEventListener("click", () => { | ||
| // show a greeting alert in the inspected page | ||
| chrome.devtools.inspectedWindow.eval('alert("Hello from the DevTools extension!");'); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| // Update the Memory display. | ||
| setInterval(() => { | ||
| chrome.system.memory.getInfo((data) => { | ||
| if (availableMemoryCapacity) { | ||
| availableMemoryCapacity.innerHTML = data.availableCapacity; | ||
| } | ||
| if (totalMemoryCapacity) { | ||
| totalMemoryCapacity.innerHTML = data.capacity; | ||
| } | ||
| }); | ||
| }, 1000); | ||
|
|
||
| // Send a message from the inspected page to DevTools. | ||
| 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 | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| // Create a connection to the background service worker. | ||
| const backgroundPageConnection = chrome.runtime.connect({ | ||
| name: "devtools-page" | ||
| }); | ||
|
|
||
| // Relay the tab ID to the background service worker. | ||
| backgroundPageConnection.postMessage({ | ||
| name: 'init', | ||
| tabId: chrome.devtools.inspectedWindow.tabId | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "name": "Custom DevTools tool", | ||
| "description": "A DevTools extension interacting with the inspected page", | ||
| "manifest_version": 3, | ||
| "version": "1.0", | ||
| "devtools_page": "devtools.html", | ||
| "content_scripts": [{ | ||
| "matches": [ | ||
| "http://*/*", | ||
| "https://*/*" | ||
| ], | ||
| "run_at": "document_idle", | ||
| "js": [ | ||
| "content_script.js" | ||
| ] | ||
| }], | ||
| "background": { | ||
| "service_worker": "service-worker.js" | ||
| }, | ||
| "permissions": [ | ||
| "system.memory" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| </head> | ||
| <body> | ||
| <h2>Custom DevTools tool</h2> | ||
|
|
||
| <h3>Memory</h3> | ||
| <div> | ||
| <b>Available Memory Capacity:</b> <span id="availableMemoryCapacity"></span> | ||
| </div> | ||
| <div> | ||
| <b>Total Memory Capacity:</b> <span id="totalMemoryCapacity"></span> | ||
| </div> | ||
|
|
||
| <h3>Send message from DevTools to inspected page</h3> | ||
| <input type="button" id="sayHello" value="Say hello to the inspected page"><!-- todo: alert is sometimes displayed twice (in "main" as well) --> | ||
| <h3>Send message from inspected page to DevTools</h3> | ||
| <p>Click somewhere in the inspected webpage.</p> | ||
| <div> | ||
| <b>Coordinates:</b> <span id="youClickedOn"></span> | ||
| </div> | ||
|
|
||
| </body> | ||
| </html> | ||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The alert is sometimes displayed twice, in this extension and in "main" branch.
No consistent repro steps yet; d/k why alert is displayed twice sometimes.
@captainbrosset