Summary
The persistence plugin's shutdown/SIGTERM handler tries to save
storageState for each session on container shutdown, but by the
time that handler runs the browser context has already been torn
down, so the save always fails with:
{"level":"warn","msg":"failed to persist storage state","userId":"joyjit","storageStatePath":"/data/profiles/<id>/storage-state.json","error":"browserContext.storageState: Target page, context or browser has been closed"}
Current Behavior
Storage state is only flushed on two triggers today:
- Idle-tab reap (30 min)
- Explicit session destroy
On container shutdown/restart there's also a final-save attempt,
but the browser context is closed before that handler runs, so the
save is a guaranteed no-op that just logs a warning.
Seen 3 times in docker logs camofox-browser:
- 2026-06-30 17:38 (
userId: deploy-e2e)
- 2026-06-30 17:54 (
userId: health-monitor)
- 2026-07-02 16:34 (
userId: joyjit, during a docker restart camofox-browser)
In each case the prior idle-flush happened to be recent enough that
on-disk state was still current, so no data was actually lost. But
that's incidental — if a restart happens shortly after real session
activity (login, cookie refresh) and before the next 30-minute idle
flush, that state is silently dropped. Restarts happen for upgrades,
crashes, or OOM, not just idle periods.
Expected Behavior
On shutdown, storage state should be persisted before the browser
context is closed, so the shutdown-time save actually captures
current state instead of racing the teardown.
Suggested Fix
In the persistence plugin's shutdown/SIGTERM handler, reorder so the
flush happens first:
// current (approximate): context is closed, then save is attempted
await browserContext.close();
await persistStorageState(browserContext); // always fails, context is gone
// suggested: flush before teardown
await persistStorageState(browserContext);
await browserContext.close();
Environment
- Repo:
jo-inc/camofox-browser
- Deployment: Docker,
camofox-browser container on parkcircus
- Observed via:
docker logs camofox-browser, cross-referenced
against a persistence runbook re-run on 2026-07-02
Summary
The persistence plugin's shutdown/SIGTERM handler tries to save
storageStatefor each session on container shutdown, but by thetime that handler runs the browser context has already been torn
down, so the save always fails with:
Current Behavior
Storage state is only flushed on two triggers today:
On container shutdown/restart there's also a final-save attempt,
but the browser context is closed before that handler runs, so the
save is a guaranteed no-op that just logs a warning.
Seen 3 times in
docker logs camofox-browser:userId: deploy-e2e)userId: health-monitor)userId: joyjit, during adocker restart camofox-browser)In each case the prior idle-flush happened to be recent enough that
on-disk state was still current, so no data was actually lost. But
that's incidental — if a restart happens shortly after real session
activity (login, cookie refresh) and before the next 30-minute idle
flush, that state is silently dropped. Restarts happen for upgrades,
crashes, or OOM, not just idle periods.
Expected Behavior
On shutdown, storage state should be persisted before the browser
context is closed, so the shutdown-time save actually captures
current state instead of racing the teardown.
Suggested Fix
In the persistence plugin's shutdown/SIGTERM handler, reorder so the
flush happens first:
Environment
jo-inc/camofox-browsercamofox-browsercontainer on parkcircusdocker logs camofox-browser, cross-referencedagainst a persistence runbook re-run on 2026-07-02