Launch Handler API: Control How Your Progressive Web App Launches

Master the Launch Handler API to configure window behavior, maintain playback continuity, and deliver native-like experiences in your PWAs

What Is the Launch Handler API?

The Launch Handler API represents a significant advancement in progressive web app (PWA) development, giving developers granular control over how their applications respond to launch events. This API addresses a fundamental challenge in modern web development: managing the user experience when users interact with your app through various entry points such as app shortcuts, deep links, or file associations.

By configuring launch behavior, you can ensure that your application provides a seamless, predictable experience regardless of how users access it. The API operates at the intersection of manifest configuration and JavaScript runtime behavior, providing both declarative configuration for simple use cases and programmatic flexibility for complex scenarios.

The Launch Handler API emerged from the Web Incubator Community Group (WICG) to address these considerations systematically, providing a standardized mechanism for controlling launch behavior across different platforms and devices. When combined with AI-powered automation features, PWAs can deliver intelligent, context-aware experiences that rival native applications.

Key Capabilities

What the Launch Handler API enables for your PWAs

Window Behavior Control

Control whether launches use existing windows or create new ones, preventing unwanted window proliferation.

Navigation Management

Determine whether launched URLs navigate existing content or are communicated via JavaScript for custom handling.

File Handling

Receive FileSystemHandle objects for files passed during launch, enabling native-like file workflows.

State Continuity

Maintain application state during launches, essential for media players and productivity applications.

Web App Manifest Configuration

The web app manifest serves as the configuration hub for PWA behavior, and the launch_handler member extends this configuration to encompass launch-specific behaviors. When you add launch_handler to your manifest, you declare how your application should respond when launched through various mechanisms. The manifest configuration establishes the default behavior, while the JavaScript API provides runtime flexibility for handling specific launch scenarios.

The launch_handler member is structured as a dictionary containing configuration options, with client_mode serving as the primary configuration property. This design accommodates future expansion with additional properties beyond client_mode, allowing the specification to evolve without breaking existing implementations.

Basic Configuration Example

{
 "name": "Music Player",
 "shortcuts": [
 { "name": "Now Playing", "url": "/" },
 { "name": "Library", "url": "/library" },
 { "name": "Favorites", "url": "/favorites" }
 ],
 "launch_handler": {
 "client_mode": "focus-existing"
 }
}

This configuration ensures that when users activate app shortcuts, the application focuses the existing window rather than creating new windows that might interrupt music playback.

Client Mode Values Explained

The client_mode property accepts several values, each representing a distinct launch handling strategy. Understanding these values requires recognizing their implications for both user experience and application state management.

auto (Default)

The auto value represents the default behavior, allowing the user agent to make contextually appropriate decisions. On mobile devices that typically support only single app instances, the user agent might choose to navigate existing windows. Conversely, on desktop platforms where multiple windows are standard, the user agent might create new windows to prevent potential data loss from navigation.

navigate-new

The navigate-new mode creates a new web app client to load the launch's target URL. This approach guarantees isolation between launch events and existing application state, making it suitable for applications that process independent tasks.

navigate-existing

The navigate-existing mode brings existing app instances into focus and navigates them to the target URL. If no existing client is open, the behavior falls back to navigate-new. This mode provides a middle ground between single-instance enforcement and task isolation.

focus-existing

The focus-existing mode represents the most sophisticated launch handling strategy. When an existing client is open, it comes into focus without navigation, and the target URL is communicated via LaunchParams for programmatic handling. This mode is essential for applications like music players, where interrupting playback to navigate away would degrade the user experience.

Array Syntax for Fallback

The client_mode property also supports array syntax for graceful degradation across platforms:

{
 "launch_handler": {
 "client_mode": ["focus-existing", "navigate-existing", "auto"]
 }
}

The user agent selects the first supported value from the array, falling back to subsequent options as needed. Our web development team can help you choose the right client mode for your specific use case.

The JavaScript API: LaunchQueue and LaunchParams

The JavaScript API provides the programmatic mechanism for handling launches within your application's code. Understanding these interfaces is essential for implementing sophisticated launch handling.

LaunchQueue Interface

The LaunchQueue interface is exposed through the window.launchQueue property and enables applications to register consumers that process incoming launch events. The LaunchQueue design addresses a subtle but important race condition: launch events could fire before page scripts attach event listeners.

By buffering launches until a consumer is set, LaunchQueue ensures no launch events are missed.

LaunchParams Interface

LaunchParams encapsulates all information about a launch event:

  • targetURL: The URL that triggered the launch (must be within scope)
  • files: Array of FileSystemHandle objects for file launches

Setting Up a LaunchConsumer

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

 // Extract the track parameter from the URL
 const track = params.get("track");
 if (track) {
 audio.src = track;
 title.textContent = new URL(track).pathname.slice(1);
 audio.play();
 }
 }
 });
}

Implementing the Launch Handler API requires expertise in modern JavaScript development to ensure robust cross-browser compatibility and optimal performance.

Complete Launch Handler Implementation
1if ("launchQueue" in window) {2 window.launchQueue.setConsumer((launchParams) => {3 // Handle target URL launches4 if (launchParams.targetURL) {5 const url = new URL(launchParams.targetURL);6 7 // Route based on URL path8 if (url.pathname.startsWith("/library")) {9 navigateToLibrary();10 } else if (url.pathname.startsWith("/favorites")) {11 showFavorites();12 } else if (url.pathname.startsWith("/discover")) {13 openDiscover();14 }15 16 // Extract query parameters17 const params = url.searchParams;18 const track = params.get("track");19 if (track) {20 audio.src = track;21 audio.play();22 }23 }24 25 // Handle file launches if applicable26 if (launchParams.files && launchParams.files.length > 0) {27 for (const handle of launchParams.files) {28 processFileHandle(handle);29 }30 }31 });32}

Media Applications

Music and video applications represent the canonical use case for focus-existing mode. When users activate app shortcuts while media is playing, maintaining playback continuity is essential for user satisfaction. The Launch Handler API enables this behavior by preventing navigation that would interrupt playback.

Media applications can extract launch parameters to update their interface while maintaining playback. A music player shortcut to the library section can focus the existing player window and navigate to the library view without stopping the currently playing track.

Browser Support and Compatibility

The Launch Handler API currently has limited browser support, primarily available in Chromium-based browsers including Chrome and Edge. The API is marked as experimental, and developers should verify support before relying on it in production applications.

Feature Detection

if ("launchQueue" in window && "setConsumer" in window.launchQueue) {
 // Launch Handler API is supported
 implementLaunchHandling();
} else {
 // Provide fallback behavior
 console.log("Launch Handler API not supported");
}

Platform Considerations

Browser support varies significantly across platforms, particularly regarding multi-instance capabilities. Mobile platforms typically support only single app instances, influencing how user agents interpret the auto client mode. Desktop platforms may support multiple windows, allowing navigate-new behavior without the same concerns about resource constraints.

Frequently Asked Questions

Ready to Build Better PWAs?

Our team specializes in progressive web app development with modern APIs like the Launch Handler. Let's discuss how we can enhance your web applications.

Sources

  1. MDN Web Docs: Launch Handler API - Comprehensive technical reference covering interfaces, client_mode values, and code examples
  2. Chrome for Developers: Launch Handler API - Practical implementation guide with use cases and best practices
  3. WICG Web App Launch Handler Specification - Official specification with detailed algorithms and conformance requirements
  4. MDN Web Docs: LaunchQueue - Detailed LaunchQueue interface documentation
  5. MDN Web Docs: LaunchParams - LaunchParams properties and usage details