Skip to content

Restore scan results from the page after the background stops - #673

Open
PekSec wants to merge 1 commit into
RetireJS:masterfrom
PekSec:extension-restore-results
Open

PekSec wants to merge 1 commit into
RetireJS:masterfrom
PekSec:extension-restore-results

Conversation

@PekSec

@PekSec PekSec commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Problem

The toolbar badge shows a number, but opening the popup shows an empty list and scans the page again.

The browser stops the idle background after about 30 seconds (the service worker in Chrome, the event page in Firefox). Results lived only in background memory, so they were lost, while the browser kept the badge. Opening the popup started a new background, which cleared every badge, waited 3 seconds and downloaded all of the page's scripts again.

Change

A small content script keeps a copy of the tab's results in the page. When the background has no results for a tab, it asks the page first.

  • Opening the popup shows the earlier results at once. Nothing is downloaded again and the badge stays.
  • The copy belongs to the document, so results are still per top-level navigation. It is gone on navigation, tab close and extension reload.
  • No storage API is used. This is how the extension kept results before Modernize browser extensions with prebuilt packages and shared popup #624 (content.js).
  • The content script is passive. It stores and returns what the background sends and never sends a message itself. The background checks the shape of what comes back before using it.
  • A scan that was running when the background stopped runs again after the restore.
  • Tabs opened before the extension was installed or reloaded have no content script. They keep the current behaviour: wait 3 seconds, then scan the page's scripts.

No new permission is needed. The content script matches http://*/* and https://*/*, which <all_urls> already covers.

Testing

  • 41 unit tests pass (cd chrome/build && npm test). New: content.test.cjs and the restart cases in runtime.test.cjs.
  • browser-smoke.cjs has a new step: it stops the service worker, opens the popup again and checks that the same libraries are listed, the badge is unchanged and no script is requested again. It passes in Chrome 158 for both Chrome packages.
  • The Firefox smoke check passes in Firefox 161. It does not stop the background; I checked that scenario in Firefox once with a throwaway script.
  • The three prebuilt packages are rebuilt. Their service workers also pick up the node/lib/retire.js change from da66c52, which the prebuilt packages on master do not have yet.

AI-assisted implementation.

🤖 Generated with Claude Code

The browser stops the idle background after about 30 seconds, but keeps
the badge. Results lived only in background memory, so opening the popup
on a tab whose badge showed findings started an empty worker, cleared
the badges, waited 3 seconds and downloaded every script again.

A passive content script now keeps a copy of the tab's results in the
page. A restarted background restores from it before answering the
popup, so the first snapshot already has the results and nothing is
downloaded again. The copy is per document: it is gone on navigation,
tab close and extension reload. No storage API is used.

Tabs without a copy (opened before the extension was installed or
reloaded) still use the existing 3 second wait and rescan.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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