Skip to content

Fix Flow key loss after MV3 service worker restart - #24

Merged
crisng95 merged 1 commit into
crisng95:mainfrom
Bl0ck154:codex/mv3-flowkey-bootstrap
Aug 18, 2026
Merged

crisng95 merged 1 commit into
crisng95:mainfrom
Bl0ck154:codex/mv3-flowkey-bootstrap

Conversation

@Bl0ck154

Copy link
Copy Markdown
Contributor

What changes

This makes the Manifest V3 background worker hydrate its persisted state on
every worker evaluation, not only after an extension install or a full Chrome
startup. The initialization is shared by lifecycle events so concurrent alarms
or startup events do not open duplicate WebSocket connections.

It also adds a small Node-based regression test for a cold worker start with a
stored Flow bearer token.

Why

MV3 service workers may be suspended and recreated while Chrome itself remains
open. In that path onStartup and onInstalled do not run. The previous code
therefore recreated the local-agent WebSocket while flowKey was still its
module default (null), even though a valid token already existed in
chrome.storage.local. The bridge then reported itself connected but had no
Flow authentication until the Flow tab happened to make another authorized
request.

Validation

node --check extension/background.js

node tests/extension_mv3_bootstrap.test.cjs

The regression test verifies that a cold worker start reads the stored token
before connecting, announces flowKeyPresent: true, forwards the token to the
agent, and does not duplicate initialization when lifecycle events overlap.

@crisng95
crisng95 marked this pull request as ready for review August 18, 2026 09:09
@crisng95
crisng95 merged commit 66e8596 into crisng95:main Aug 18, 2026
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.

2 participants