Skip to content

feat(engine): configurable first-boot init timeout for whatsapp-web.js (WWEBJS_AUTH_TIMEOUT_MS)#383

Merged
rmyndharis merged 1 commit into
mainfrom
feat/wwebjs-auth-timeout
Jun 21, 2026
Merged

feat(engine): configurable first-boot init timeout for whatsapp-web.js (WWEBJS_AUTH_TIMEOUT_MS)#383
rmyndharis merged 1 commit into
mainfrom
feat/wwebjs-auth-timeout

Conversation

@rmyndharis

Copy link
Copy Markdown
Owner

Problem

On slow first boots (e.g. WSL2 or low-resource containers), the whatsapp-web.js engine's fixed 30s wait for WhatsApp Web to finish loading can expire before the QR code is generated — the session fails during init with no QR ever produced. Reported in #353 (the second, still-open half of that issue; the spawn ps ENOENT crash from the same report shipped in v0.4.4).

Change

Expose whatsapp-web.js's native authTimeoutMs option through a new opt-in env var:

# Allow up to 2 minutes for the first-boot init wait (milliseconds):
WWEBJS_AUTH_TIMEOUT_MS=120000
  • Unset / non-positive-integer → unchanged. Falls back to the wwebjs default (30000ms), so existing deployments behave exactly as before.
  • Resolved the same way as the existing WWEBJS_WEB_VERSION pin — read + validated directly in the adapter (resolveAuthTimeoutMs()), so it applies uniformly to both the factory-fallback and plugin-registration construction paths without threading config through two places.

Why authTimeoutMs is the right knob

Tracing wwebjs Client.initialize() (v1.34.7):

  1. puppeteer.launch() — puppeteer's own launch timeout
  2. page.goto(WhatsWebURL, { timeout: 0 })no timeout, waits for load
  3. inject() — polls for WhatsApp Web to become ready, bounded by authTimeoutMs (default 30000), else throws auth timeout

The QR is only emitted after step 3 succeeds. On a slow boot the WA-Web bundle can take >30s to initialize, so inject() throws before any QR — exactly the reported symptom. Raising authTimeoutMs extends precisely this window. engine.initialize() is awaited with no outer Promise.race, so nothing caps the value.

Known limitation (deliberate): this does not extend the puppeteer.launch() timeout (step 1, Chromium process startup). For the reported symptom (past launch, stuck at init) that's correct; a separate launch-timeout knob can be added later if needed.

Tests

  • New resolveAuthTimeoutMs unit tests: unset → default, valid positive int parsed, invalid values (0, negative, float, non-numeric, units) rejected.
  • Backend gate green: lint clean, nest build clean, 990/990 unit tests pass.

Docs

  • .env.example: documented WWEBJS_AUTH_TIMEOUT_MS.
  • docs/12-troubleshooting-faq.md: new "QR generation times out on slow first boot (WSL2 / low-resource)" entry.

Refs #353.

…s (WWEBJS_AUTH_TIMEOUT_MS)

On slow first boots (e.g. WSL2 or low-resource containers) the engine's fixed 30s
wait for WhatsApp Web to finish loading can expire before the QR code is generated,
aborting startup with no QR ever produced.

Expose the whatsapp-web.js-native `authTimeoutMs` option through a new optional
`WWEBJS_AUTH_TIMEOUT_MS` env var (milliseconds). Resolved the same way as the
existing `WWEBJS_WEB_VERSION` pin: read + validated directly in the adapter, so it
applies to both the factory-fallback and plugin-registration construction paths.
Unset (or a non-positive-integer value) keeps the wwebjs default (30000ms), so
existing deployments are unchanged.

Refs #353.
@rmyndharis rmyndharis force-pushed the feat/wwebjs-auth-timeout branch from da9f690 to be478c5 Compare June 21, 2026 03:45
@rmyndharis rmyndharis merged commit 6570dec into main Jun 21, 2026
5 checks passed
@rmyndharis rmyndharis deleted the feat/wwebjs-auth-timeout branch June 21, 2026 03:47
rmyndharis added a commit that referenced this pull request Jun 21, 2026
…WEBJS_AUTH_TIMEOUT_MS) (#383)

Lets slow first boots (WSL2, low-resource containers) extend the fixed 30s wait for WhatsApp Web to load before QR generation. Unset keeps the 30000ms default. Closes #353.
rmyndharis added a commit that referenced this pull request Jun 21, 2026
Cut v0.4.7 — smart webhook filters (#379), WWEBJS_AUTH_TIMEOUT_MS (#383), toast anti-spam (#293), Postgres webhook-JSON crash fix (#385).
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.

2 participants