Back to Content

LaunchQueue: setConsumer() method

files/en-us/web/api/launchqueue/setconsumer/index.md

latest1.5 KB
Original Source

{{APIRef("Launch Handler API")}}{{SeeCompatTable}}

The setConsumer() method of the {{domxref("LaunchQueue")}} interface is used to declare the callback that will handle custom launch navigation handling in a progressive web app (PWA). Such custom navigation is initiated via {{domxref("Window.launchQueue")}} when a PWA has been launched with a launch_handler client_mode value of focus-existing, navigate-new, or navigate-existing.

Syntax

js-nolint
setConsumer(callback)

Parameters

  • callback
    • : A callback function that handles custom navigation for the PWA. The callback is passed a {{domxref("LaunchParams")}} object instance as a parameter.

Return value

undefined.

Examples

js
if ("launchQueue" in window) {
  window.launchQueue.setConsumer((launchParams) => {
    if (launchParams.targetURL) {
      const params = new URL(launchParams.targetURL).searchParams;

      // Assuming a music player app that gets a track passed to it to be played
      const track = params.get("track");
      if (track) {
        audio.src = track;
        title.textContent = new URL(track).pathname.slice(1);
        audio.play();
      }
    }
  });
}

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also