This guide explains how to test the new MV3 service worker implementation that uses proper lifecycle management and lazy initialization.
The new service worker implementation addresses the "Receiving end does not exist" errors by:
- Lazy Initialization - Only initializes when first needed
- Proper Wake-Up Handling - Handles service worker termination/restart
- Event-Driven Architecture - Responds to events rather than staying persistent
- State Persistence - Uses chrome.storage for state management
-
Load the test script in the extension context:
// Copy and paste the contents of test-new-sw.js into the browser console // when viewing popup-test.html or popup-test-new-sw.html
-
Run the tests:
// Run all tests window.testNewServiceWorker.runAllTests() // Or run individual tests window.testNewServiceWorker.testPing() window.testNewServiceWorker.testInitialization() window.testNewServiceWorker.testHotkeys()
-
Temporarily replace manifest.json:
cp manifest.json manifest-backup.json cp manifest-test.json manifest.json
-
Reload the extension in Chrome
-
Test the new service worker using the test pages
-
Restore original manifest:
cp manifest-backup.json manifest.json
- Purpose: Verify basic communication
- Expected: Service worker responds with
{ status: 'ready', initialized: false/true }
- Purpose: Verify lazy initialization works
- Expected: First ping triggers initialization, second shows
initialized: true
- Purpose: Verify command handling
- Expected: Returns keyboard shortcuts for spaces commands
- Purpose: Verify popup parameter generation
- Expected: Returns URL parameters for popup windows
- Purpose: Verify error handling
- Expected: Handles failed requests gracefully
- Purpose: Verify concurrent request handling
- Expected: Handles multiple simultaneous requests
- Purpose: Verify service worker stays responsive
- Expected: Responds after idle periods
- No "Receiving end does not exist" errors
- Service worker initializes on first request
- All tests pass consistently
- Console shows proper initialization logs
- Persistent connection errors
- Service worker not responding after idle
- Initialization failures
- Missing functionality
Test service worker starting up...
Test service worker activated...
Starting test service worker initialization...
Test service worker initialization complete
Test SW message received: ping
✅ Passed: 7
❌ Failed: 0
📈 Success Rate: 100%
If all tests pass:
- Replace the current service worker with the new implementation
- Update popup.js to use the service-worker-client.js utility
- Test the full extension functionality
- Deploy the changes
If tests fail:
- Check console logs for specific error messages
- Verify manifest.json configuration
- Check Chrome extension permissions
- Debug specific failing test cases
// In Chrome DevTools > Application > Service Workers
// Look for the extension's service worker and check its status// Watch for these key messages:
// - "Test service worker starting up..."
// - "Test service worker initialization complete"
// - "Test SW message received: ping"// Test just the ping functionality
window.testNewServiceWorker.testPing()
// Test initialization specifically
window.testNewServiceWorker.testInitialization()- The test service worker (
service-worker-test.js) is a simplified version focused on testing the patterns - The full implementation (
service-worker.js) includes all the original functionality - Tests should be run in the extension context (not regular web pages)
- Service worker termination and restart is normal behavior in MV3