Scope

The scope property defines the navigation boundary of your PWA. It determines which URLs are considered part of your application and which will open in a regular browser tab.

Purpose

The scope controls:

  • App boundaries: Which pages stay in the PWA window

  • Browser context: When to open the system browser

  • Service worker registration: What URLs the service worker controls

  • User experience: Seamless navigation within your app vs external links

Configuration

/config/packages/pwa.yaml
pwa:
    manifest:
        enabled: true
        scope: "/"  # Controls all URLs under your domain

If not specified, the scope defaults to the directory containing the manifest file.

How Scope Works

URLs Within Scope

URLs within the scope remain in your PWA window:

Within scope (stays in PWA):

  • https://example.com/app/

  • https://example.com/app/dashboard

  • https://example.com/app/settings/profile

Outside scope (opens in browser):

  • https://example.com/

  • https://example.com/blog/

  • https://example.com/about

  • https://other-domain.com/

Relationship with start_url

The start_url must be within the scope:

Common Scope Patterns

Pattern 1: Root Scope (Most Common)

Control the entire domain:

Use when:

  • Your PWA is the entire website

  • You want all pages in the PWA experience

  • Single-page applications

Examples: Gmail, Twitter PWA, most SPAs

Pattern 2: Application Subfolder

Limit PWA to a specific section:

Use when:

  • PWA is part of a larger website

  • Marketing pages are separate

  • Multiple apps on same domain

Examples:

  • /app/ - Main application

  • / - Marketing website

  • /blog/ - Blog (opens in browser)

Pattern 3: Versioned Scope

Include version in scope:

Use when:

  • Running multiple app versions

  • Gradual migration strategies

  • A/B testing different versions

Pattern 4: Language-Specific Scope

Separate scopes per language:

Use when:

  • Different manifests per language

  • Localized app experiences

  • Regional variations

Practical Examples

Example 1: E-commerce Site

Marketing site + shop PWA:

Result:

  • /shop/products - PWA window ✓

  • /shop/cart - PWA window ✓

  • / - Opens in browser (marketing)

  • /about - Opens in browser (corporate)

Example 2: SaaS Dashboard

App separate from landing pages:

Result:

  • /dashboard/* - PWA ✓

  • /pricing - Browser (public page)

  • /docs - Browser (documentation)

Example 3: Multi-tenant Application

Each tenant has own scope:

Result:

  • /tenant/acme-corp/* - PWA for this tenant ✓

  • /tenant/other-corp/* - Opens in browser

  • /admin/* - Opens in browser

Example 4: Full-Site PWA

Everything is the PWA:

Result:

  • All URLs on your domain stay in PWA ✓

  • External links open in browser

Advanced Configurations

Multiple Manifests for Different Scopes

Serve different manifests for different sections:

Dynamic Scope Based on User

Scope and Service Workers

The scope in your manifest should align with your service worker scope:

Testing Your Scope

1. Check Manifest in DevTools

2. Test Navigation Behavior

Click links to verify:

  • Internal links stay in PWA window

  • External links open in browser

  • Cross-scope links open in browser

3. Test with Different URLs

Common Mistakes

1. start_url Outside Scope

Fix:

2. Too Restrictive Scope

Impact: Users navigating to /app/settings will leave the PWA.

Fix:

3. Forgetting Trailing Slash

Best practice: Use trailing slash for directory-based scopes:

4. Mismatched Service Worker Scope

Impact: Service worker may not control all PWA pages.

Fix:

Scope Validation Errors

Error: start_url not within scope

Solution: Adjust start_url or scope:

Error: Invalid scope format

Solution: Use proper path format:

Platform-Specific Behavior

iOS/Safari

  • Respects scope for navigation

  • Service worker scope must match or be narrower

  • May show URL bar for out-of-scope navigation

Android/Chrome

  • Strongly enforces scope boundaries

  • Out-of-scope links open in Chrome Custom Tabs

  • Clear visual indication when leaving PWA

Desktop Browsers

  • Opens new tab for out-of-scope URLs

  • May show browser UI for external navigation

  • Varies by browser implementation

Best Practices

1. Start Broad, Refine Later

2. Align with Site Architecture

Match your URL structure:

3. Consider Future Growth

Leave room for expansion:

4. Document Your Scope Decision

5. Test Across Platforms

Verify scope behavior on:

  • iOS Safari

  • Android Chrome

  • Desktop Chrome

  • Desktop Edge

  • Other target browsers

Debugging Scope Issues

Check Current Scope

Monitor Navigation Events

Validate scope Configuration

  • Start URL - Where your PWA starts (must be within scope)

  • ID - Unique identifier for your PWA

  • Display Mode - How the app window appears

Summary

Scope best practices:

  • ✓ Use / for full-site PWAs

  • ✓ Use /app/ to separate PWA from marketing

  • ✓ Ensure start_url is always within scope

  • ✓ Align manifest scope with service worker scope

  • ✓ Use trailing slashes for directory-based scopes

  • ✓ Test navigation behavior across scope boundaries

  • ✓ Document why you chose a specific scope

  • ✗ Don't make scope too restrictive

  • ✗ Don't forget to test on real devices

  • ✗ Don't change scope frequently (affects PWA identity)

Last updated

Was this helpful?