Skip to content
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

Merged
merged 6 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand Down
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`
- : {{WebExtAPIRef("runtime.OnPerformanceWarningCategory")}}. The category of the warning.
- `severity`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Rob--W Is this also an object?, e.g. OnPerformanceWarningSeverity

Copy link

Choose a reason for hiding this comment

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

{
  "id": "OnPerformanceWarningCategory",
  "type": "string",
  "enum": ["content_script"],
  "description": "The performance warning event category, e.g. 'content_script'."
},
{
  "id": "OnPerformanceWarningSeverity",
  "type": "string",
  "enum": ["low", "medium", "high"],
  "description": "The performance warning event severity. Will be 'high' for serious and user-visible issues."
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kzar exactly, hence the question.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 OnPerformanceWarningCategory and OnPerformanceWarningSeverity as types?

Copy link
Member

Choose a reason for hiding this comment

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

Yes.

- : {{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}}
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 is for a slow content script in the listening extension.

{{WebExtExamples("h2")}}

## Browser compatibility

{{Compat}}
Original file line number Diff line number Diff line change
@@ -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}}
2 changes: 2 additions & 0 deletions files/en-us/mozilla/firefox/releases/124/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading