mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#7649
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7262
Author: @SpicyMarinara
Created: 10/7/2026
Status: ✅ Merged
Merged: 10/7/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/extension-watchdog-background-7260📝 Commits (5)
2060f26fix: keep client extensions alive in background tabs64fb8affix: start client extensions reliably in Safari and test Restart2f8f39afix: keep other stopped extensions stopped on Restartb79798bfix: forget stopped extensions when the injector unmounts6cc4b83fix: dismiss a stopped notice once the extension is no longer stopped📊 Changes
7 files changed (+265 additions, -7 deletions)
View changed files
📝
CHANGELOG.md(+1 -0)📝
docs/development/personal-extensions.md(+1 -1)➕
e2e/personal-extension-restart.e2e.ts(+113 -0)📝
packages/client/src/components/layout/PersonalExtensionInjector.tsx(+41 -2)📝
packages/client/src/localization/locales/en.json(+3 -0)📝
packages/server/src/routes/personal-extensions.routes.ts(+15 -4)📝
scripts/regressions/extension-security.regression.ts(+91 -0)📄 Description
Linked issue
Closes #7260
Reported on Discord by spacyH (Safari 27 on macOS), who also traced the watchdog code and suggested the fix direction. Thank you!
Why this change
Client extensions stopped working whenever you left the Marinara tab for about 10 seconds. The extension's panel and top-bar buttons stayed on screen, but every click did nothing, and nothing told you why.
The cause is the sandbox's heartbeat watchdog (served by
GET /api/personal-extensions/:id/sandbox.html). The extension worker sends a heartbeat every second, and the watchdog stopped the worker after 5 seconds without one. Browsers throttle or pause timers in hidden tabs, during sleep and in suspended mobile apps, so the heartbeat stalls through no fault of the worker. When the watchdog then ran (while hidden, or as soon as you came back), it stopped a healthy worker. The host never heard that the worker was gone (it only logged to the console), so the dead controls stayed. The developer docs already promised that "the host removes all contributions when the worker is stopped"; that was not true for watchdog stops.What changed
packages/server/src/routes/personal-extensions.routes.ts, sandbox bootstrap): each tick now restarts the 5-second silence window when the page is hidden (document.hidden, which a nested iframe takes from the top-level tab) or when the tick itself arrives more than 2 seconds after the previous one. A late tick proves this page's own timers were held back (background throttling, sleep, a frozen page, a long main-thread stall), so a missing heartbeat is expected. A worker that hangs on a visible page is still stopped after the same 5 seconds.stopped: true. The host (PersonalExtensionInjector.tsx) then removes that extension's buttons, menu items and panels, and shows a notice, "{name} stopped working. Its buttons and panels are hidden until you restart it.", with a Restart button. Restart re-runs the normal start-up for that extension only, if it is still enabled and approved. Other stopped extensions stay stopped until you restart them, their code changes, they are turned off and on again, or the page reloads. Ordinary extension errors (a thrown error in a handler, a failed start-up promise) do not set the flag and behave as before.new Worker(). WebKit loads the worker script after the constructor returns, so the load failed (WebKitBlobResource error 1, then "Browser extension worker failed"). The extension never started, and its top-bar button never appeared. The URL is now kept for the sandbox's lifetime and released when the iframe is removed. This is the "top-bar button missing after a fresh load" bug from the issue (see below).en.jsononly (3 keys underextensions.runtime.*).scripts/regressions/extension-security.regression.ts: runs the served sandbox bootstrap in anode:vmcontext with a fake clock, fakedocument.hiddenand a fakeWorker, then checks: a hidden tab with stalled heartbeats is not stopped (30 s of 1 Hz ticks plus a 60 s throttled gap), coming back gives a fresh window, a 120 s late tick on a visible page is not a hang, and a worker silent for over 5 s on a visible page is stopped and reported withstopped: true. It also checks that the worker blob URL is not revoked during start-up. Onorigin/stagingit fails withA hidden page must not stop a worker whose heartbeat is throttled. With only the early revoke put back, it fails withThe worker blob URL must outlive the Worker constructor call.e2e/personal-extension-restart.e2e.ts(desktop-chromium): runs the realPersonalExtensionInjectorwith a fixture sandbox. An ordinary error keeps the button. Astopped: trueerror removes the button and the iframe and shows the notice. Restart then creates a fresh iframe for the same extension and brings the button back, while a second stopped extension stays stopped. It fails with a no-op Restart handler, withoutrestartRequestin the effect deps, without the stopped-extension check in setup, and with the staging injector.docs/development/personal-extensions.md: two sentences on the new watchdog behaviour. Translations are tracked in #7261.[Unreleased].Top-bar button missing after a fresh load (the minor bug in the issue)
Root cause found and fixed here: the early
URL.revokeObjectURL(workerUrl)described above. In Playwright's WebKit, against a real approved client extension, the top-bar button was missing on 8 of 8 fresh loads before the change and present on 8 of 8 after it, about 0.5 s after load. Chromium resolves blob URLs when the Worker is created, so it was never affected (5 of 5 before and after). Real Safari probably wins the race sometimes, which fits "often missing". Before this PR, the watchdog then stopped the worker that never started, and nothing told the user.Validation
pnpm checkpasses locallyCONTRIBUTING.mdAgent-run checks (not a substitute for the boxes above):
pnpm checkpassed;pnpm regression:extensions-securitypassed and fails on theorigin/stagingroute as described above;e2e/personal-extension-restart.e2e.tsande2e/topbar-accessibility.e2e.tspassed on desktop-chromium. Local CodeRabbit: 0 findings on the first commit. Later runs found two things, both fixed: Restart also restarted other stopped extensions (2f8f39af7), and the stopped list should be cleared when the injector unmounts (b79798b01). The GitHub CodeRabbit thread about the source-text-only Restart check was fixed with the e2e above (64fb8af24).Local real-browser probe (temporary spec, not committed) with a real approved client extension and the real server sandbox, desktop Chromium:
document.hidden: with this PR the button still worked afterwards ("Probe 4"); with the staging watchdog the worker was stopped, the button stayed on screen, and clicking it did nothing (title stuck at "Probe 3"). This is the reported symptom.Page.setWebLifecycleState) or stalling the sandbox thread for 7 s did not stop the worker, before or after. Chromium delivers the queued heartbeats before the overdue timer, which is why Chromium users rarely hit this.Manual verification notes
while (true) {}, click it on a visible tab, and check that within about 6 seconds its buttons and panel disappear and the notice "{name} stopped working." appears with Restart.throw new Error("x")inside a button handler) keeps its buttons and does not show the stopped notice.Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)Docs:
docs/development/personal-extensions.mdandCHANGELOG.mdupdated;[docs-i18n]follow-up is #7261.UI evidence (if applicable)
The only new UI is a standard Sonner notice with a Restart action, styled by the app's existing toast theme. No screenshot yet; it appears only after the sandbox stops a hung extension.
Summary by CodeRabbit
Bug Fixes
New Features
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.