TaskSignal: prioritychange event

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Note: This feature is available in Web Workers.

The prioritychange event is sent to a TaskSignal if its priority is changed.

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

js
addEventListener("prioritychange", (event) => { })

onprioritychange = (event) => { }

Event type

A TaskPriorityChangeEvent. Inherits from Event.

Event TaskPriorityChangeEvent

Event properties

TaskPriorityChangeEvent.previousPriority

Indicates the previous priority of the task (before it was changed). The new/updated priority is read from event.target.priority (TaskSignal.priority).

Examples

The example below shows how to listen for the prioritychange event on a TaskSignal.

First we create a controller, and add an event listener to its signal. When handling the event we use previousPriority on the event to get the original priority and TaskSignal.priority on the event target to get the new/current priority.

The task is then posted, passing in the signal, and then we immediately change the priority.

js
if ("scheduler" in this) {
  // Declare a TaskController, setting its signal priority to 'user-blocking'
  const controller = new TaskController({ priority: "user-blocking" });

  // Listen for 'prioritychange' events on the controller's signal.
  controller.signal.addEventListener("prioritychange", (event) => {
    const previousPriority = event.previousPriority;
    const newPriority = event.target.priority;
    myLog(`Priority changed from ${previousPriority} to ${newPriority}.`);
  });

  // Post task using the controller's signal.
  // The signal priority sets the initial priority of the task
  scheduler.postTask(
    () => {
      myLog("Task 1");
    },
    { signal: controller.signal },
  );

  // Change the priority to 'background' using the controller
  controller.setPriority("background");
}

Note: The code above uses a custom logging function myLog() to log to the text area below. This is hidden as it isn't relevant to the example.

The output below demonstrates shows that the task's priority changed from user-blocking to background. This happens before the task is executed, but could also happen when the task is running.

Specifications

Specification
Prioritized Task Scheduling
# eventdef-tasksignal-prioritychange
Prioritized Task Scheduling
# dom-tasksignal-onprioritychange

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
prioritychange event
Chrome – Full support
Chrome 94 (Release date: 2021-09-21)
footnote Full support
Edge – Full support
Edge 94 (Release date: 2021-09-24)
footnote Full support
Firefox – Full support
Firefox 142 (Release date: 2025-08-19)
footnote Full support
Opera – Full support
Opera 80 (Release date: 2021-10-05)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 94 (Release date: 2021-09-21)
footnote Full support
Firefox for Android – Full support
Firefox for Android 142 (Release date: 2025-08-19)
footnote Full support
Opera Android – Full support
Opera Android 66 (Release date: 2021-12-15)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 17 (Release date: 2022-05-04)
footnote Full support
WebView Android – Full support
WebView Android 94 (Release date: 2021-09-21)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support