Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(bootstrap): classify both shapes of the ownerless inject rejection
Yudhi Armyndharisfae39da4324c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3a43a2907..16ff8f4cc 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Fixed+- **A benign whatsapp-web.js rejection no longer reads like a crash** — the same un-awaited `framenavigated` re-injection that already logs at `WARN` when the page goes away was logged at `ERROR` in its other shape, where the navigation lands before WhatsApp Web has defined its module registry; it appears at the first boot after the pinned WhatsApp Web build moves under a warm profile, and the session reaches ready unaided.++### Fixed+- **A data export now reports the media it had to leave behind** — an over-budget attachment is replaced with the same omitted marker that media skipped on the way in gets, so a truncated backup was indistinguishable from a complete one both on inspection and on restore; the response now carries `omittedInlineMedia` alongside `skippedTables`, and the dashboard warns after a download that dropped anything.- **A node that has observed the loss of its session lease no longer writes `FAILED` for that session** — engine callbacks were fenced only by a local liveness check, so between a heartbeat detecting the loss and the teardown it schedules, a dying generation could park a row a peer already owned in `FAILED`, which is excluded from both the boot reset and the takeover sweep by design and so left the session outside every automatic recovery path on every node until an operator restarted it by hand. The fence engages from the heartbeat tick that detects the loss, not from the moment the lease lapses, so a window remains.- **Thirteen settings that did nothing under Docker now take effect** — Compose forwards environment explicitly and has no `env_file`, so `BAILEYS_MARK_ONLINE_ON_CONNECT`, `BAILEYS_SYNC_FULL_HISTORY`, `WEBHOOK_CONTACT_DETAILS`, `ALLOW_UNSIGNED_INGRESS`, `STORE_EPHEMERAL_MESSAGES`, `RESOLVE_LID_TO_PHONE`, `SIMULATE_TYPING`, `MCP_ENABLED`, `SEARCH_ENABLED`, `SERVE_DASHBOARD`, `CACHE_ENABLED`, `DATABASE_LOGGING` and `MAIN_DATABASE_SYNCHRONIZE` never reached the container however the operator's `.env` was written — the MCP server could not be enabled at all, `SEARCH_ENABLED=false` did not disable the search route it documents, and `BAILEYS_MARK_ONLINE_ON_CONNECT` left the paired phone's notifications suppressed for as long as the gateway stayed connected.diff --git a/src/config/process-error-monitor.spec.ts b/src/config/process-error-monitor.spec.tsindex 50cdd2a05..1440372ef 100644--- a/src/config/process-error-monitor.spec.ts+++ b/src/config/process-error-monitor.spec.ts@@ -98,6 +98,30 @@ describe('registerUnhandledRejectionHandler', () => {expect(String(warns[0][1]?.reason)).toContain('Execution context was destroyed');});+ // The SAME #982 listener produces a second shape. When the navigation lands on a page whose+ // WhatsApp Web bundle has not defined its module registry yet — which is what a build change does+ // to a warm profile — the pending evaluate throws on `window.require` instead of dying with the+ // context. Observed live: two of these at the first boot after the pinned WA Web build moved, then+ // the session reached READY on its own with no lastError, and a restart on the same build produced+ // none. Same cause, same benign outcome, so it must not read like a crash either.+ it('treats the window.require variant of the same framenavigated race as the same benign class', () => {+ const { handler, errors, warns } = register();+ handler(new TypeError('window.require is not a function'));+ expect(errors).toHaveLength(0);+ expect(warns).toHaveLength(1);+ expect(warns[0][0]).toMatch(/navigation or engine teardown/i);+ expect(String(warns[0][1]?.reason)).toContain('window.require is not a function');+ });++ // The downgrade is scoped to that one call, not to `window.require` anywhere: a rejection naming a+ // DIFFERENT missing global is not this race and must stay an error.+ it('still errors on an unrelated missing-global rejection', () => {+ const { handler, errors, warns } = register();+ handler(new TypeError('window.somethingElse is not a function'));+ expect(warns).toHaveLength(0);+ expect(errors).toHaveLength(1);+ });+it('stringifies a non-Error rejection without throwing', () => {const { handler, errors } = register();expect(() => handler('a bare string')).not.toThrow();diff --git a/src/config/process-error-monitor.ts b/src/config/process-error-monitor.tsindex 5fcc80983..17634a547 100644--- a/src/config/process-error-monitor.ts+++ b/src/config/process-error-monitor.ts@@ -15,14 +15,23 @@ interface RejectionLogger extends FatalLogger {}/**- * Puppeteer raises this when an isolated world is disposed while an `evaluate` is still waiting for an- * execution context — i.e. the page went away underneath it.+ * The two shapes an ownerless `inject()` rejection takes (#982). One cause, so one classification.*- * Deliberately duplicated from the whatsapp-web.js adapter's own predicate rather than imported: that- * module pulls whatsapp-web.js in eagerly, and this one is loaded during bootstrap, where the engine- * must stay lazy. Keep the two in sync.+ * 1. `execution context was destroyed` — Puppeteer disposed the isolated world while an `evaluate`+ * was still waiting for a context, i.e. the page went away underneath it.+ * 2. `window.require is not a function` — the navigation landed on a page whose WhatsApp Web bundle+ * has not defined its module registry yet, so the evaluate reaches `window.require` before it+ * exists. Observed at the first boot after the pinned WA Web build moved under a warm profile:+ * twice, then the session reached READY unaided, and a restart on the same build produced none.+ *+ * Only the FIRST alternative mirrors the whatsapp-web.js adapter's `isExecutionContextDestroyedError`+ * — deliberately duplicated rather than imported, because that module pulls whatsapp-web.js in eagerly+ * and this one loads during bootstrap, where the engine must stay lazy. Keep that alternative in sync+ * with it. The second is monitor-only ON PURPOSE: the adapter uses its predicate to advise about a+ * stale browser profile (#663/#708), and a missing `window.require` is not evidence of that, so+ * teaching it there would produce a confidently wrong advisory.*/-const PAGE_CONTEXT_LOST_REJECTION = /execution context was destroyed/i;+const PAGE_CONTEXT_LOST_REJECTION = /execution context was destroyed|window\.require is not a function/i;/*** Register an `uncaughtExceptionMonitor` that routes an otherwise-fatal uncaught exception through the