Skip to content

Fix MV3 service worker wake after restart#3

Draft
drogers0 wants to merge 5 commits intomainfrom
issue-2-service-worker-startup
Draft

Fix MV3 service worker wake after restart#3
drogers0 wants to merge 5 commits intomainfrom
issue-2-service-worker-startup

Conversation

@drogers0
Copy link
Copy Markdown
Owner

Summary

  • register MV3 onStartup and onInstalled listeners so Chrome wakes the extension worker on browser/profile start and install/update
  • add chrome.runtime.sendMessage error handling in fetch.js
  • write an immediate failed fetch_status via native messaging when no receiving end exists, so usage-check fails fast instead of timing out

Testing

  • npm run build
  • npm test

Closes #2

@drogers0
Copy link
Copy Markdown
Owner Author

Ran the recommended startup/restart smoke validation locally on branch issue-2-service-worker-startup, but fetch never started because the configured extension ID is not currently active in this Chrome profile.

Evidence:

  • ./bin/usage-check --json --debug times out with no .cache/fetch_status.json updates
  • native host launch log shows no new entries during the run

Unblock:

  1. Load unpacked extension from this repo path: /Users/david/Documents/git/llm-usage/extension
  2. Copy the current extension ID from chrome://extensions
  3. Run ./install.sh

After that, rerun cold-start smoke (usage-check, restart Chrome, usage-check) and this PR can be reassessed for ready-to-merge.

@drogers0
Copy link
Copy Markdown
Owner Author

Update: retried smoke validation after setting EXTENSION_ID=ciekcbfgdpcfhlbohdjdachagblijjao via ./install.sh.

Result remains blocked:

  • both pre-restart and post-restart runs of ./bin/usage-check --json --debug timed out
  • no .cache/fetch_status.json written
  • native host launch log shows no new entries during these attempts

This indicates the extension ID configured in .env still does not correspond to an active loaded unpacked extension in the Chrome profile being used.

Please confirm in chrome://extensions that ID ciekcbfgdpcfhlbohdjdachagblijjao is present and enabled for the unpacked extension loaded from /Users/david/Documents/git/llm-usage/extension.

… coverage

- Fix fetch page hardcoding ok:true regardless of worker status (now derives from status.ok)
- Fix ingest_extension_result silently accepting partial results (now rejects missing providers)
- Fix shell readlink -f portability for macOS BSD readlink
- Fix bash 3.2 empty array expansion under set -u
- Add shared typed fetch contract (FetchEnvelope, FetchStatus, FetchUsageMessage)
- Add request_id correlation and deadline_ms timeout propagation end-to-end
- Move extension/fetch.js into TypeScript build pipeline (src/extension/fetch.ts)
- Switch extension builds to IIFE format (manifest lacks type:module)
- Extract buildFetchStatus as pure testable function
- Extract parseCopilotUsage as pure function, eliminate DOM parsing duplication
- Add withHiddenTab lifecycle helper with single-ownership tab cleanup
- Add unwrapScriptResult helper for consistent script result handling
- Replace inline node -e status parsing with read-fetch-status.ts helper
- Add validateEnvelope with actual field validation
- Remove dead native-host launcher (usage_cache_host.sh)
- Add --non-interactive flag and LLM_USAGE_NMH_DIR/LLM_USAGE_CACHE_DIR overrides
- Add 66 tests across 10 test files (ingest, render, shell smoke, setup validation,
  fetch contract, background contract, copilot parser, extension base, read-fetch-status)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Service worker fails to wake after computer restart

1 participant