Problem
Clipboard work creates and closes an offscreen document from service-worker handlers without one serialized lifecycle. Concurrent requests or a service-worker restart can race document creation, message delivery, and teardown.
Evidence
- extension/background.js:89-116 manages the offscreen document lifecycle.
- extension/background.js:134-169 performs clipboard messaging against that shared resource.
- extension/background.js:569-605 exposes call paths that can overlap or resume after worker lifecycle changes.
Proposed work
Serialize offscreen-document acquisition and clipboard operations. Reconcile actual document state before create or close, keep the document alive while operations are pending, and make each request return a clear success or failure result after the clipboard action completes.
Acceptance criteria
- Start with a failing test for two concurrent clipboard requests racing document creation.
- Only one offscreen document is created and it remains available until all pending operations finish.
- A service-worker restart can recover the existing document state.
- Failed message delivery is reported and does not leave a stuck lifecycle flag.
- Tests cover concurrent copy, restart recovery, and close-after-last-user behavior.
Non-goals
- Changing copied content formats.
- Redesigning extension UI.
Problem
Clipboard work creates and closes an offscreen document from service-worker handlers without one serialized lifecycle. Concurrent requests or a service-worker restart can race document creation, message delivery, and teardown.
Evidence
Proposed work
Serialize offscreen-document acquisition and clipboard operations. Reconcile actual document state before create or close, keep the document alive while operations are pending, and make each request return a clear success or failure result after the clipboard action completes.
Acceptance criteria
Non-goals