Launch Handler

circle-exclamation

Overview

The Launch Handler API allows you to control how your PWA is launched and navigated. It determines whether the app uses an existing window or creates a new one, and how the target launch URL is handled.

Key Capabilities:

  • Control window reuse behavior

  • Handle navigation to launch URLs programmatically

  • Receive launch parameters in JavaScript

  • Implement custom launch logic

Configuration

Basic Configuration

/config/packages/pwa.yaml
pwa:
    manifest:
        enabled: true
        launch_handler:
            client_mode: "focus-existing"

Multiple Client Modes (Fallback)

Specify multiple modes with fallback behavior:

The browser will try the first mode, falling back to the next if unsupported.

Complete Example

Client Modes

focus-existing

Description: Focuses the most recently used window without navigating. The target URL is passed to JavaScript via LaunchQueue for custom handling.

Behavior:

  • ✅ Reuses existing window

  • ✅ Brings window to foreground

  • ❌ Does NOT navigate automatically

  • ✅ Target URL available via window.launchQueue

Use Cases:

  • Email clients - focus existing window, load new message

  • Task managers - focus app, add new task from URL

  • Note-taking apps - focus window, create note

  • Chat applications - focus window, open conversation

  • Single-instance apps that handle URLs programmatically

Example:

JavaScript Handler:

Description: Navigates the most recently used window to the target URL, and also provides the URL via LaunchQueue for additional handling.

Behavior:

  • ✅ Reuses existing window

  • ✅ Automatically navigates to target URL

  • ✅ Target URL also available via window.launchQueue

Use Cases:

  • Web browsers - navigate to new URL

  • Documentation viewers - load new page

  • Content platforms - navigate to shared content

  • Apps where automatic navigation is desired

Example:

JavaScript Handler:

Description: Creates a new window/tab and navigates to the target URL. Useful for apps where multiple instances make sense.

Behavior:

  • ✅ Creates new window

  • ✅ Automatically navigates to target URL

  • ✅ Multiple concurrent instances possible

  • ✅ Target URL available via window.launchQueue

Use Cases:

  • Document editors - each document in its own window

  • Image editors - open each image separately

  • Development tools - multiple project windows

  • Apps benefiting from multiple instances

Example:

JavaScript Handler:

auto (default)

Description: Browser chooses the best behavior for the platform.

Behavior:

  • Mobile: Typically uses navigate-existing (single instance)

  • Desktop: May use navigate-new (multiple instances)

  • Platform-optimized behavior

Use Cases:

  • Default mode if not specified

  • When you want platform-optimized behavior

  • Apps that should work well everywhere

Example:

Browser Support

Browser
Version
Support

Chrome (Desktop)

92+

✅ Full support

Chrome (Android)

92+

✅ Full support

Edge (Desktop)

92+

✅ Full support

Safari

All

❌ Not supported

Firefox

All

❌ Not supported

circle-info

Fallback: When not supported, the browser falls back to default launch behavior (typically opens new window).

LaunchQueue API

The LaunchQueue API allows you to handle launches programmatically in your JavaScript code.

Basic Usage

Complete Example: Task Manager

Handling File Launches

When combined with File Handling API:

Use Cases

1. Email Client

Focus existing window and open specific email:

2. Multi-Document Editor

Allow multiple document windows:

3. Single-Instance Media Player

Reuse window and queue new media:

4. Note-Taking App

Focus window and create note from shared text:

5. Platform-Optimized Behavior

Let browser decide best behavior:

Testing

1. Feature Detection

Check if LaunchQueue API is available:

2. Test Launch Scenarios

3. DevTools Testing

4. Real-World Testing

Best Practices

1. Always Set Launch Consumer

2. Handle All Launch Scenarios

3. Provide Fallback for Unsupported Browsers

4. Log Launch Events

5. Combine with Other APIs

Common Mistakes

1. Not Setting Consumer Early

Problem:

Solution:

2. Assuming API Availability

Problem:

Solution:

3. Not Handling targetURL Properly

Problem:

Solution:

4. Ignoring Files Parameter

Problem:

Solution:

Troubleshooting

Launch Handler Not Working

Problem: LaunchQueue consumer not receiving events

Checklist:

  • ✓ Check browser support (Chrome/Edge 92+)

  • ✓ Verify PWA is installed (not running in browser tab)

  • ✓ Ensure launch_handler is in manifest

  • ✓ Set consumer before first launch completes

  • ✓ Check DevTools console for errors

  • ✓ Verify manifest is valid JSON

Multiple Windows Opening

Problem: New window opens instead of reusing existing

Solutions:

  • Check client_mode is set to "focus-existing" or "navigate-existing"

  • Verify PWA is launched from installed app (not browser tab)

  • Ensure manifest is correctly loaded

  • Test on supported browser

targetURL Not Correct

Problem: LaunchQueue receives wrong URL

Solutions:

  • Check start_url in manifest

  • Verify URL used to launch app

  • Inspect launchParams.targetURL value

  • Ensure proper URL encoding

Resources

  • Launch Handler API: https://developer.chrome.com/docs/web-platform/launch-handler/

  • LaunchQueue Spec: https://wicg.github.io/sw-launch/

  • MDN LaunchQueue: https://developer.mozilla.org/en-US/docs/Web/API/LaunchQueue

  • Chrome Platform Status: https://chromestatus.com/feature/5722383233056768

Last updated

Was this helpful?