feat(engine): configurable first-boot init timeout for whatsapp-web.js (WWEBJS_AUTH_TIMEOUT_MS)#383
Merged
Merged
Conversation
2 tasks
…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.
da9f690 to
be478c5
Compare
Merged
rmyndharis
added a commit
that referenced
this pull request
Jun 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 ENOENTcrash from the same report shipped in v0.4.4).Change
Expose whatsapp-web.js's native
authTimeoutMsoption through a new opt-in env var:# Allow up to 2 minutes for the first-boot init wait (milliseconds): WWEBJS_AUTH_TIMEOUT_MS=120000WWEBJS_WEB_VERSIONpin — 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
authTimeoutMsis the right knobTracing wwebjs
Client.initialize()(v1.34.7):puppeteer.launch()— puppeteer's own launch timeoutpage.goto(WhatsWebURL, { timeout: 0 })— no timeout, waits forloadinject()— polls for WhatsApp Web to become ready, bounded byauthTimeoutMs(default 30000), else throwsauth timeoutThe 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. RaisingauthTimeoutMsextends precisely this window.engine.initialize()is awaited with no outerPromise.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
resolveAuthTimeoutMsunit tests: unset → default, valid positive int parsed, invalid values (0, negative, float, non-numeric, units) rejected.nest buildclean, 990/990 unit tests pass.Docs
.env.example: documentedWWEBJS_AUTH_TIMEOUT_MS.docs/12-troubleshooting-faq.md: new "QR generation times out on slow first boot (WSL2 / low-resource)" entry.Refs #353.