-
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
Add runtime.on performance warning #32222
Changes from 4 commits
1f442bc
b1832c7
49d3f48
670f349
31fc90e
b8bb8f2
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,64 @@ | ||
--- | ||
title: runtime.onPerformanceWarning | ||
slug: Mozilla/Add-ons/WebExtensions/API/runtime/onPerformanceWarning | ||
page-type: webextension-api-event | ||
browser-compat: webextensions.api.runtime.onPerformanceWarning | ||
--- | ||
|
||
{{AddonSidebar}} | ||
|
||
This event fires when a runtime performance issue is detected for the extension. Observe this event to be notified of runtime performance problems with your extension. | ||
|
||
## Syntax | ||
|
||
```js-nolint | ||
browser.runtime.onPerformanceWarning.addListener(listener) | ||
browser.runtime.onPerformanceWarning.removeListener(listener) | ||
browser.runtime.onPerformanceWarning.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)` | ||
- : Checks whether at least one 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: | ||
|
||
- `details` | ||
|
||
- : `object`. An object with the following properties: | ||
|
||
- `category` | ||
- : A {{WebExtAPIRef("runtime.OnPerformanceWarningCategory")}} object indicating the category of the warning. | ||
- `severity` | ||
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 Is this also an object?, e.g. 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. @rebloor If it helps, here are the entries from /toolkit/components/extensions/schemas/runtime.json:
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. @kzar exactly, hence the question. 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 inline the potential values for now; I'll clarify with other engineers whether we really want to expose the supported values on an object. If so, then we can update the documentation to add extra articles with the enum values. 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. I requested clarification at w3c/webextensions#456 (comment). Let's wait a week or so to allow for an answer before merging this PR. I think that the most likely outcome is that we would retain these objects. Let's shape this patch towards that assumption since it is the least amount of work for you. 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 I see that @kzar responded to w3c/webextensions#456 (comment) - do I read that correctly that we are agreeing to document 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. Yes. |
||
- : `string`. The performance warning event severity. One of "low", "medium", or "high". | ||
- `tabId` {{optional_inline}} | ||
- : `integer`. The ID of the tab that the performance warning relates to, if any. | ||
- `description` | ||
- : `string`. An explanation of what the warning means, possibly with information on how to address it. | ||
|
||
## Examples | ||
|
||
```js | ||
function handlePerformanceWarning(details) { | ||
console.log(`Performance warning: ${details.description}`); | ||
} | ||
|
||
browser.runtime.onPerformanceWarning.addListener(handlePerformanceWarning); | ||
``` | ||
|
||
{{WebExtExamples}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,22 @@ | ||||||
--- | ||||||
title: runtime.OnPerformanceWarningCategory | ||||||
slug: Mozilla/Add-ons/WebExtensions/API/runtime/OnPerformanceWarningCategory | ||||||
page-type: webextension-api-type | ||||||
browser-compat: webextensions.api.runtime.OnPerformanceWarningCategory | ||||||
--- | ||||||
|
||||||
{{AddonSidebar}} | ||||||
|
||||||
The category of warning that dispatched the {{WebExtAPIRef("runtime.onPerformanceWarning")}} event. | ||||||
|
||||||
## Type | ||||||
|
||||||
Values of this type are strings. Possible values are: | ||||||
|
||||||
- `"content_script"`: The performance warning originated from a content script. | ||||||
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.
Suggested change
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. Note: avoid ambiguity: the event is for content scripts of the extension itself, not others.
rebloor marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
{{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.
Is it not an object, but a string that holds one of the enum values.