Skip to main content
Service Worker support is a new feature in v0.3. It enables your wallet to run in the background, providing persistent connectivity and event handling.

Overview

Running your wallet in a service worker enables:
  • Background Processing: Keep your wallet active even when the main application is closed
  • Persistent Storage: Use IndexedDB for reliable data persistence
  • Event Handling: Process incoming payments and settlements in the background
  • Improved UX: Faster response times and better reliability

Quick Setup

The v0.3 SDK provides ultra-simplified service worker setup with automatic registration and identity management:

Service Worker Implementation

Create a service worker file that handles communication:
That’s all you need! The Worker class automatically:
  • Handles message routing
  • Manages wallet state
  • Processes events
  • Handles cleanup

Example: Storage and Identity Management

Here’s a complete example with storage and identity management:

Using IndexedDB Storage

For service workers, IndexedDB is recommended over LocalStorage:
IndexedDB is recommended for service workers because it’s accessible from both the main thread and service worker context, and can store larger amounts of data.

Handling Events

Service workers can process wallet events in the background:

Advanced: Custom Service Worker

If you need custom service worker logic, you can extend the Worker class:

Best Practices

Always use IndexedDB for service worker wallets:
Store your identity securely and load it on initialization:
Implement proper error handling for service worker operations:

Troubleshooting

If you encounter IndexedDB errors:
  1. Check browser console for specific error messages
  2. Ensure the database name and version are consistent
  3. Clear browser data if the database schema changed
If you encounter IndexedDB errors:
  1. Check browser console for specific error messages
  2. Ensure the database name and version are consistent
  3. Clear browser data if the database schema changed
If you experience message timeouts:
  1. Check that the Worker is properly started in the service worker
  2. Verify network connectivity
  3. Check for errors in the service worker console

Next Steps