Skip to content

[bug] Allow service worker registration on custom schemes for macOS (eg. tauri://) #13031

@praneetloke

Description

@praneetloke

Describe the bug

Image

It's impossible to register a service worker when a Tauri app is using the default tauri:// (or any other) scheme. Please see the Additional Context section for more info.

Reproduction

  • Create a simple UI and add a call to navigator.serviceWorker.register() to register a service worker script.
  • Build the app with tauri build for macOS.
  • Run the app and see the failure in the developer tools related to registering the service worker.

Expected behavior

Tauri apps should be allowed to register service worker on custom schemes and not have to resort to using the localhost plugin.

Full tauri info output

(This output is from a Windows machine but my app is cross-platform. Let me know if you would like the output from a machine running macOS too.)


[✔] Environment
    - OS: Windows 10.0.22631 x86_64 (X64)
    ✔ WebView2: 134.0.3124.72
    ✔ MSVC: Visual Studio Build Tools 2022
    ✔ rustc: 1.85.0 (4d91de4e4 2025-02-17)
    ✔ cargo: 1.85.0 (d73d2caf9 2024-12-31)
    ✔ rustup: 1.28.0 (6e19fbec7 2025-03-02)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc
    - node: 22.13.1
    - yarn: 4.7.0
    - npm: 10.9.2
    - bun: 1.1.33

[-] Packages
    - tauri 🦀: 2.3.1
    - tauri-build 🦀: 2.0.6
    - wry 🦀: 0.50.3
    - tao 🦀: 0.32.7
    - @tauri-apps/api : not installed!
    - @tauri-apps/cli : 2.2.5 (outdated, latest: 2.3.1)

[-] Plugins
    - tauri-plugin-shell 🦀: 2.2.0
    - @tauri-apps/plugin-shell : not installed!
    - tauri-plugin-log 🦀: 2.2.3
    - @tauri-apps/plugin-log : not installed!
    - tauri-plugin-process 🦀: 2.2.0
    - @tauri-apps/plugin-process : not installed!
    - tauri-plugin-fs 🦀: 2.2.0
    - @tauri-apps/plugin-fs : not installed!
    - tauri-plugin-opener 🦀: 2.2.6
    - @tauri-apps/plugin-opener : not installed!
    - tauri-plugin-dialog 🦀: 2.2.0
    - @tauri-apps/plugin-dialog : not installed!
    - tauri-plugin-updater 🦀: 2.5.1
    - @tauri-apps/plugin-updater : not installed!
    - tauri-plugin-deep-link 🦀: 2.2.0
    - @tauri-apps/plugin-deep-link : not installed!
    - tauri-plugin-http 🦀: 2.3.0
    - @tauri-apps/plugin-http : not installed!
    - tauri-plugin-sql 🦀: 2.2.0
    - @tauri-apps/plugin-sql : not installed!
    - tauri-plugin-single-instance 🦀: 2.2.2
    - @tauri-apps/plugin-single-instance : not installed!
    - tauri-plugin-window-state 🦀: 2.2.1
    - @tauri-apps/plugin-window-state : not installed!

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../../app/dist
    - devUrl: http://localhost:3333/
    - bundler: Vite

Stack trace


Additional context

Past issues that were opened but closed because the issue authors chose to use the localhost plugin but I don't believe that should be the solution every time someone runs into this issue.

tauri-apps/wry#389
#12214

The problem seems to stem from the fact that WebKit checks the protocol of the service worker page: https://github.com/WebKit/WebKit/blob/main/Source/WebCore/workers/service/ServiceWorkerContainer.cpp#L194-L200.

I think what is needed here is some functionality similar to Electron's register the custom protocol as privileged using protocol.registerSchemeAsPrivileged. Here's how Electron patched support service worker for Chromium: electron/electron#20248

Interestingly, this came up in an old issue related to adding support for custom schemes but it looks like it fell through the cracks over the extended conversation that took place in #323 (comment).

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: upstreamThis issue is blocked by upstream dependencies and we need to wait or contribute upstream fixestype: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions