diff --git a/files/en-us/mozilla/add-ons/webextensions/api/runtime/index.md b/files/en-us/mozilla/add-ons/webextensions/api/runtime/index.md index c1193e53e3aa231..0dea473d18b807b 100644 --- a/files/en-us/mozilla/add-ons/webextensions/api/runtime/index.md +++ b/files/en-us/mozilla/add-ons/webextensions/api/runtime/index.md @@ -31,6 +31,10 @@ It also provides messaging APIs enabling you to: - : Result of a call to {{WebExtAPIRef("runtime.requestUpdateCheck()")}}. - {{WebExtAPIRef("runtime.OnInstalledReason")}} - : The reason that the {{WebExtAPIRef("runtime.onInstalled")}} event is being dispatched. +- {{WebExtAPIRef("runtime.OnPerformanceWarningCategory")}} + - : The category of warning that dispatched the {{WebExtAPIRef("runtime.onPerformanceWarning")}} event. +- {{WebExtAPIRef("runtime.OnPerformanceWarningSeverity")}} + - : The severity of warning that dispatched the {{WebExtAPIRef("runtime.onPerformanceWarning")}} event. - {{WebExtAPIRef("runtime.OnRestartRequiredReason")}} - : The reason that the {{WebExtAPIRef("runtime.onRestartRequired")}} event is being dispatched. @@ -96,6 +100,8 @@ It also provides messaging APIs enabling you to: - : Fired when a message is sent from either an extension process or a content script. - {{WebExtAPIRef("runtime.onMessageExternal")}} - : Fired when a message is sent from another extension. Cannot be used in a content script. +- {{WebExtAPIRef("runtime.onPerformanceWarning")}} + - : Fired when a runtime performance issue is detected for the extension. - {{WebExtAPIRef("runtime.onRestartRequired")}} - : Fired when the device needs to be restarted. diff --git a/files/en-us/mozilla/add-ons/webextensions/api/runtime/onperformancewarning/index.md b/files/en-us/mozilla/add-ons/webextensions/api/runtime/onperformancewarning/index.md new file mode 100644 index 000000000000000..3a57739329f6b35 --- /dev/null +++ b/files/en-us/mozilla/add-ons/webextensions/api/runtime/onperformancewarning/index.md @@ -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` + - : {{WebExtAPIRef("runtime.OnPerformanceWarningCategory")}}. The category of the warning. + - `severity` + - : {{WebExtAPIRef("runtime.OnPerformanceWarningSeverity")}}. The severity of the warning. + - `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}} diff --git a/files/en-us/mozilla/add-ons/webextensions/api/runtime/onperformancewarningcategory/index.md b/files/en-us/mozilla/add-ons/webextensions/api/runtime/onperformancewarningcategory/index.md new file mode 100644 index 000000000000000..b74c01acdfbd761 --- /dev/null +++ b/files/en-us/mozilla/add-ons/webextensions/api/runtime/onperformancewarningcategory/index.md @@ -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 is for a slow content script in the listening extension. + +{{WebExtExamples("h2")}} + +## Browser compatibility + +{{Compat}} diff --git a/files/en-us/mozilla/add-ons/webextensions/api/runtime/onperformancewarningseverity/index.md b/files/en-us/mozilla/add-ons/webextensions/api/runtime/onperformancewarningseverity/index.md new file mode 100644 index 000000000000000..caf9f8afb7a5418 --- /dev/null +++ b/files/en-us/mozilla/add-ons/webextensions/api/runtime/onperformancewarningseverity/index.md @@ -0,0 +1,24 @@ +--- +title: runtime.OnPerformanceWarningSeverity +slug: Mozilla/Add-ons/WebExtensions/API/runtime/OnPerformanceWarningSeverity +page-type: webextension-api-type +browser-compat: webextensions.api.runtime.OnPerformanceWarningSeverity +--- + +{{AddonSidebar}} + +The severity of warning that dispatched the {{WebExtAPIRef("runtime.onPerformanceWarning")}} event. + +## Type + +Values of this type are strings. Possible values are: + +- `"low"` +- `"medium"` +- `"high"` + +{{WebExtExamples("h2")}} + +## Browser compatibility + +{{Compat}} diff --git a/files/en-us/mozilla/firefox/releases/124/index.md b/files/en-us/mozilla/firefox/releases/124/index.md index b6afbbe48f70336..c26e0b096753b0d 100644 --- a/files/en-us/mozilla/firefox/releases/124/index.md +++ b/files/en-us/mozilla/firefox/releases/124/index.md @@ -58,6 +58,8 @@ This article provides information about the changes in Firefox 124 that affect d ## Changes for add-on developers +- Adds the {{WebExtAPIRef("runtime.onPerformanceWarning")}} event that enables extensions to obtain information when the browser detects that the extension has a runtime performance issue such as a slow-running content script ([Firefox bug 1861445](https://bugzil.la/1861445)). + ### Removals ### Other