Skip to content

A capture's progress survives the popup being closed - #65

Open
vhladiienko wants to merge 1 commit into
Open-Capture:mainfrom
vhladiienko:fix/popup-progress-after-reopen
Open

vhladiienko wants to merge 1 commit into
Open-Capture:mainfrom
vhladiienko:fix/popup-progress-after-reopen

Conversation

@vhladiienko

Copy link
Copy Markdown

Summary

A full-page capture runs in the service worker for seconds, but the popup that started it is destroyed the moment it loses focus (MV3). When reopened mid-capture, the popup sat on "No capture yet" while the page visibly scrolled. The running capture is now queryable, and its end is broadcast:

popup A: click "Capture full page" ──► orchestrator.captureFullPage
                                        reportProgress(done, total) ── module state
popup A destroyed on blur               (runtime broadcasts continue; nobody listens)

popup B opened ─ captureState ──► { done, total }
                                  ──► adopt: progress bar + "N of M" + disabled buttons

capture finishes
  setLastCaptureUi() ──────► storage.local
  broadcast captureFinished ──► popup B: bar down, buttons back,
                                 restore this capture (or show the classified failure)
  • orchestrator.ts keeps captureProgress as module state — its lifetime is exactly the capture's, because the capture in flight is what keeps the worker alive. A worker evicted mid-capture wakes blank and truthfully answers "nothing running"; there is no stored flag to go stale. Cleared in a finally, so a capture that died halfway does not answer as if it were still going.
  • background/index.ts answers captureState, and broadcasts captureFinished after setLastCaptureUi on success (so an attached popup restores this capture, not the one before it) and with the classified failure in the message listener's catch.
  • popup.ts asks about a running capture before rendering the last one's result — the restore path reads tens of megabytes of preview out of blob-store and would flash the previous capture under the bar. If a capture is running it attaches; the existing captureProgress message listener then drives the bar as before. The popup that started the capture is untouched: it still learns the outcome from its own awaited reply.

A side effect of the failure broadcast: a capture that fails while no popup is listening (e.g. the active tab changed) no longer loses the reason — a popup reopened afterwards shows what happened instead of silently reverting.

Evidence

New e2e tests in e2e/progress.spec.ts (drive the real handleRequest path):

  • Before: a popup opened mid-capture showed "No capture yet" with enabled buttons; the capture's progress block existed only in the destroyed popup's memory. There was no mechanism to ask the worker what was running.
  • After:
✓ a popup reopened while a capture runs shows the capture's progress, then its result
    #captureProgress visible, buttons disabled, "N of M" status mid-run;
    after captureFinished: bar hidden, buttons enabled, report visible
✓ a popup attached to a capture that fails shows why instead of hanging on the bar
    after the active tab is stolen: bar hidden, error status with is-error class
✓ a long capture reports which slice it is on (existing test, unchanged behaviour)

3 passed; full suite 91/92 (the one failure, watermark tiled pattern, fails
identically on main without this patch); tsc clean; 110 unit tests pass

Merge Danger

Door: two-way

Additive message types and a changed popup-open order; reverting restores prior behaviour. Nothing persisted, no schema, no permissions.

Blast Radius: popup + background messaging

The only behaviour change beyond the reopen fix: any failed capture request now emits a captureFinished broadcast that non-attached popups ignore (guarded by an adopt flag), and a popup opened onto a running capture disables its buttons until the broadcast lands — which is what the original popup already did while its own capture ran.

A full-page capture runs in the service worker for as long as the page is
tall, and the popup that started it does not survive a click outside
itself - MV3 tears a popup down the moment it loses focus. The popup a
user reopened mid-capture was a new instance that never heard the capture
begin: it sat on "No capture yet" while the page visibly scrolled, and
nothing showed progress until the capture finished.

The running capture now records how far it is - module state in the
orchestrator, whose lifetime is exactly the capture's, since the capture
in flight is what keeps the worker alive. A worker evicted mid-capture
wakes blank and truthfully answers "nothing running"; no stored flag to
go stale. The handler answers a captureState question with it, and a
captureFinished broadcast tells an attached popup when it is over: after
setLastCaptureUi on success, so the popup restores this capture rather
than the one before it, and carrying the classified failure on error, so
"the active tab changed" reaches the user instead of a bar that silently
never fills.

A popup now asks about a running capture before rendering the last one's
result, attaches to it when it finds one (bar, count, disabled buttons),
and hands over to the result - or the error - when the broadcast lands.
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.

1 participant