-
Notifications
You must be signed in to change notification settings - Fork 22.5k
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
Complete devtools.inspectedWindow #28131
base: main
Are you sure you want to change the base?
Changes from 2 commits
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
title: devtools.inspectedWindow.getResources() | ||
slug: Mozilla/Add-ons/WebExtensions/API/devtools/inspectedWindow/getResources | ||
page-type: webextension-api-function | ||
browser-compat: webextensions.api.devtools.inspectedWindow.getResources | ||
--- | ||
|
||
{{AddonSidebar()}} | ||
|
||
Retrieves the list of resources from the inspected page. | ||
|
||
## Syntax | ||
|
||
```js-nolint | ||
let gettingResources = browser.devtools.inspectedWindow.getResources() | ||
``` | ||
|
||
### Parameters | ||
|
||
This function takes no parameters. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Chrome's documentation, this function takes a callback parameter and does not return a promise. https://developer.chrome.com/docs/extensions/reference/api/devtools/inspectedWindow#method-getResources I tested and verified this behavior in Chrome 126.0.6478.127 (Official Build) (x86_64). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On MDN we are using the conventional of omitting the callback in favor of specifying a Promise value. But because we don't support this in Firefox and Chrome doesn't support Promises in their devtools API either, I wouldn't mind being explicit with the callback here. Probably makes sense to explicitly document that Chrome doesn't support Promise in devtools namespace, which is a deviation from all other MV3 APIs that now support Promises: https://issues.chromium.org/issues/41483013 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Rob--W, yesterday I didn't realize that Safari supports this method and returns a Promise (when called without a callback argument). Since Chrome still doesn't support Promises on DevTools APIs, would it make more sense to explicitly document the callback, to stick with the current convention, or something else? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's stick to the Promise convention. Note that the APIs are documented with the browser namespace which Chrome doesn't support yet. So the webextension-polyfill might work here. |
||
|
||
### Return value | ||
|
||
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) fulfilled with an array of {{WebExtAPIRef("devtools.inspectedWindow.Resource")}}. If the request fails, the promise is rejected with an error message. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Chrome returns |
||
|
||
{{WebExtExamples("h2")}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
<!-- | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are | ||
// met: | ||
// | ||
// * Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// * Redistributions in binary form must reproduce the above | ||
// copyright notice, this list of conditions and the following disclaimer | ||
// in the documentation and/or other materials provided with the | ||
// distribution. | ||
// * Neither the name of Google Inc. nor the names of its | ||
// contributors may be used to endorse or promote products derived from | ||
// this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
--> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
--- | ||
title: devtools.inspectedWindow.onResourceAdded | ||
slug: Mozilla/Add-ons/WebExtensions/API/devtools/inspectedWindow/onResourceAdded | ||
page-type: webextension-api-event | ||
browser-compat: webextensions.api.devtools.inspectedWindow.onResourceAdded | ||
--- | ||
|
||
{{AddonSidebar()}} | ||
|
||
Fired when a resource is added to the inspected page. | ||
|
||
## Syntax | ||
|
||
```js-nolint | ||
browser.devtools.inspectedWindow.onResourceAdded.addListener(listener) | ||
browser.devtools.inspectedWindow.onResourceAdded.removeListener(listener) | ||
browser.devtools.inspectedWindow.onResourceAdded.hasListener(listener) | ||
``` | ||
|
||
Events have three functions: | ||
|
||
- `addListener(listener)` | ||
- : Adds a listener to this event. | ||
- `removeListener(listener)` | ||
- : Stop listening to this event. The `listener` argument is the listener to remove. | ||
- `hasListener(listener)` | ||
- : Check whether `listener` is registered for this event. Returns `true` if it is listening, `false` otherwise. | ||
|
||
## addListener syntax | ||
|
||
### Parameters | ||
|
||
- `listener` | ||
|
||
- : The function called when this event occurs. The function is passed this argument: | ||
|
||
- `resource` | ||
- : {{WebExtAPIRef('devtools.inspectedWindow.Resource')}}. The resource that was added. | ||
|
||
{{WebExtExamples("h2")}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
<!-- | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are | ||
// met: | ||
// | ||
// * Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// * Redistributions in binary form must reproduce the above | ||
// copyright notice, this list of conditions and the following disclaimer | ||
// in the documentation and/or other materials provided with the | ||
// distribution. | ||
// * Neither the name of Google Inc. nor the names of its | ||
// contributors may be used to endorse or promote products derived from | ||
// this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
--> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
title: devtools.inspectedWindow.onResourceContentCommitted | ||
slug: Mozilla/Add-ons/WebExtensions/API/devtools/inspectedWindow/onResourceContentCommitted | ||
page-type: webextension-api-event | ||
browser-compat: webextensions.api.devtools.inspectedWindow.onResourceContentCommitted | ||
--- | ||
|
||
{{AddonSidebar()}} | ||
|
||
Fired when a revision of the resource is committed. For example, user saves an edited version of the resource in the Developer Tools. | ||
|
||
## Syntax | ||
|
||
```js-nolint | ||
browser.devtools.inspectedWindow.onResourceContentCommitted.addListener(listener) | ||
browser.devtools.inspectedWindow.onResourceContentCommitted.removeListener(listener) | ||
browser.devtools.inspectedWindow.onResourceContentCommitted.hasListener(listener) | ||
``` | ||
|
||
Events have three functions: | ||
|
||
- `addListener(listener)` | ||
- : Adds a listener to this event. | ||
- `removeListener(listener)` | ||
- : Stop listening to this event. The `listener` argument is the listener to remove. | ||
- `hasListener(listener)` | ||
- : Check whether `listener` is registered for this event. Returns `true` if it is listening, `false` otherwise. | ||
|
||
## addListener syntax | ||
|
||
### Parameters | ||
|
||
- `listener` | ||
|
||
- : The function called when this event occurs. The function is passed this argument: | ||
|
||
- `content` | ||
- : `string` The content of the resource. | ||
- `resource` | ||
- : {{WebExtAPIRef('devtools.inspectedWindow.Resource')}}. The resource that was committed. | ||
|
||
{{WebExtExamples("h2")}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
<!-- | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are | ||
// met: | ||
// | ||
// * Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// * Redistributions in binary form must reproduce the above | ||
// copyright notice, this list of conditions and the following disclaimer | ||
// in the documentation and/or other materials provided with the | ||
// distribution. | ||
// * Neither the name of Google Inc. nor the names of its | ||
// contributors may be used to endorse or promote products derived from | ||
// this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
--> |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,37 @@ | ||||||||
--- | ||||||||
title: devtools.inspectedWindow.Resource | ||||||||
slug: Mozilla/Add-ons/WebExtensions/API/devtools/inspectedWindow/Resource | ||||||||
page-type: webextension-api-type | ||||||||
browser-compat: webextensions.api.devtools.inspectedWindow.Resource | ||||||||
--- | ||||||||
|
||||||||
{{AddonSidebar()}} | ||||||||
|
||||||||
A resource within the inspected page, such as a document, a script, or an image. This object is returned from {{WebExtAPIRef('devtools.inspectedWindow.getResources()')}}, {{WebExtAPIRef('devtools.inspectedWindow.onResourceAdded')}}, and {{WebExtAPIRef('devtools.inspectedWindow.onResourceContentCommitted')}}. | ||||||||
|
||||||||
## Type | ||||||||
|
||||||||
Values of this type are objects. They contain these properties: | ||||||||
|
||||||||
- `url` | ||||||||
- : `string`. The URL of the resource. | ||||||||
- `getContent` | ||||||||
- : `function`. Gets the content of the resource. This function takes no parameters, and returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) fulfilled with an object containing: | ||||||||
- `content` | ||||||||
- : `string`. Content of the resource, which could be encoded. | ||||||||
- `encoding` | ||||||||
- : `string`. Empty if the content is not encoded, otherwise the encoding name. | ||||||||
- `setContent` | ||||||||
- : `function`. Sets the content of the resource. This function takes these parameters: | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [mdn-linter] reported by reviewdog 🐶
Suggested change
|
||||||||
- `content` | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [mdn-linter] reported by reviewdog 🐶
Suggested change
|
||||||||
- : `string`. The new content of the resource. Only resources with the text type are supported. | ||||||||
- `commit` | ||||||||
- : `boolean`. True if the user has finished editing the resource, and the new content of the resource should be persisted; false if this is a minor change sent in progress of the user editing the resource. | ||||||||
|
||||||||
Returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) fulfilled with an error object set to undefined if the resource content was set successfully; otherwise it describes the error. | ||||||||
|
||||||||
{{WebExtExamples("h2")}} | ||||||||
|
||||||||
## Browser compatibility | ||||||||
|
||||||||
{{Compat}} |
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.
It looks like these properties are still labeled as unsupported in Firefox: https://searchfox.org/mozilla-central/source/browser/components/extensions/schemas/devtools_inspected_window.json#107-123. I also tested in Firefox Nightly 129.0a1 (2024-06-28) (64-bit) and Firefox Stable 127.0 (64-bit) and observed that they threw an "unsupported" error.
Is the intent of this change to move notes about what is (not) supported to the compat tables?