Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(wwebjs): click an operator onboarding label only inside a dialog

Yudhi Armyndharis42adda40a551
diff --git a/.env.example b/.env.example
index da32a95b7..e3cc9ef57 100644
--- a/.env.example
+++ b/.env.example
@@ -143,8 +143,9 @@ STATUS_SEED_ON_READY=false
# A freshly linked account is shown a "What's new on WhatsApp Web" modal that must be acknowledged or
# WhatsApp unlinks the companion a few minutes later. The whatsapp-web.js engine clicks it
# automatically, matching the English button label `Continue`. If your WhatsApp Web renders the modal
-# in another language, add that label here (comma-separated) — an operator-supplied label is matched
-# without the English heading check, which would otherwise reject the very modal it targets.
+# in another language, add that label here (comma-separated). An operator-supplied label is matched
+# without the English heading check, which would otherwise reject the very modal it targets, but only
+# on a button inside a visible dialog.
# WWEBJS_ONBOARDING_CONTINUE_LABELS=Continuar,Weiter,Lanjutkan
# ── Container resource limits (docker-compose only) ───────────────────────────
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 333efdfdc..52d2c3eb9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Baileys `listMessage`, `buttonsResponseMessage`, `templateButtonReplyMessage` and `listResponseMessage` now classify as `type: "text"` (they previously fell through to `unknown`). Consumers filtering on `type` will see those shapes as text. Thanks @gabrielmmoraes1999.
- The PostgreSQL data connection is pinned to UTC: parameters bind as UTC, naive timestamps read back as UTC, every pooled connection sets its session `TimeZone`, and boot fails when the effective zone is not UTC year round.
- Credentials on a `socks4://` session proxy are reported at session start as unauthenticatable: SOCKS4 sends the user name as the connect request's user id and drops the password.
+- whatsapp-web.js clicks a `WWEBJS_ONBOARDING_CONTINUE_LABELS` label only on a button inside a visible dialog. It matched any visible button with that exact text anywhere on the page, and every click counts toward the limit that moves a ready session to `action_required` ([#1679](https://github.com/rmyndharis/OpenWA/issues/1679)). Thanks @DavidgFernandes for the report.
### Fixed
@@ -104,6 +105,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- WebSocket command replies are pushed on the `message` event as well as returned through the ack callback. A client that passes an ack AND listens on `message` therefore sees each reply twice from this release; handle it in one place.
- A caller-supplied URL leaves through the session proxy from this release. Set `SESSION_PROXY_URL_FETCH=false` when a session proxy is a WhatsApp-only route that cannot reach arbitrary media hosts.
- whatsapp-web.js: `POST /api/sessions/{sessionId}/calls/{callId}/reject` answers `501` instead of a `200` that did not stop the call from ringing.
+- whatsapp-web.js: a `WWEBJS_ONBOARDING_CONTINUE_LABELS` label is clicked only on a button inside a `[role="dialog"]` or `[aria-modal="true"]` container, the same scope the `onboarding_dialog_unrecognized` warning reports labels from.
### Security
diff --git a/docs/12-troubleshooting-faq.md b/docs/12-troubleshooting-faq.md
index 3cff0ea5b..ff033b797 100644
--- a/docs/12-troubleshooting-faq.md
+++ b/docs/12-troubleshooting-faq.md
@@ -558,7 +558,8 @@ once, so the session stops instead of being silently unlinked by WhatsApp about
> flags unless `PUPPETEER_ARGS` already carries a `--lang`, but that sets the browser's language, and
> WhatsApp Web may still render in the account's own language. For another language, add the modal's
> confirm-button label to `WWEBJS_ONBOARDING_CONTINUE_LABELS` (for example `Continuar`) and restart the
-> session: the watcher runs only for the first minutes after `ready`. If your deployment gets a
+> session: the watcher runs only for the first minutes after `ready`. A configured label is clicked
+> without the English heading check, but only on a button inside a visible dialog. If your deployment gets a
> localised modal without a matching label, it is **not** auto-dismissed and the session never reaches
> `action_required`; instead it links normally, then drops to `disconnected` with reason `LOGOUT` a few
> minutes later and the device disappears from the phone's Linked devices list. That miss is not
diff --git a/src/engine/adapters/whatsapp-web-js.adapter.spec.ts b/src/engine/adapters/whatsapp-web-js.adapter.spec.ts
index 608080da2..1d75050a5 100644
--- a/src/engine/adapters/whatsapp-web-js.adapter.spec.ts
+++ b/src/engine/adapters/whatsapp-web-js.adapter.spec.ts
@@ -6907,21 +6907,27 @@ describe('probeOnboardingModal (in-page onboarding modal detection)', () => {
parentElement: FakeEl | null;
offsetParent: unknown;
getBoundingClientRect: () => { width: number; height: number };
+ getAttribute: (name: string) => string | null;
click: jest.Mock;
};
const el = (
textContent: string,
- opts: { button?: boolean; roleButton?: boolean; hidden?: boolean } = {},
- ): FakeEl => ({
- tagName: opts.button ? 'BUTTON' : 'DIV',
- role: opts.roleButton ? 'button' : null,
- textContent,
- parentElement: null,
- offsetParent: opts.hidden ? null : {},
- getBoundingClientRect: () => (opts.hidden ? { width: 0, height: 0 } : { width: 200, height: 40 }),
- click: jest.fn(),
- });
+ opts: { button?: boolean; roleButton?: boolean; hidden?: boolean; dialog?: boolean; ariaModal?: boolean } = {},
+ ): FakeEl => {
+ const role = opts.roleButton ? 'button' : opts.dialog ? 'dialog' : null;
+ return {
+ tagName: opts.button ? 'BUTTON' : 'DIV',
+ role,
+ textContent,
+ parentElement: null,
+ offsetParent: opts.hidden ? null : {},
+ getBoundingClientRect: () => (opts.hidden ? { width: 0, height: 0 } : { width: 200, height: 40 }),
+ getAttribute: (name: string) =>
+ name === 'role' ? role : name === 'aria-modal' && opts.ariaModal ? 'true' : null,
+ click: jest.fn(),
+ };
+ };
/** Wire children to a parent and return the parent, so ancestor walks have something to walk. */
const nest = (parent: FakeEl, ...children: FakeEl[]): FakeEl => {
@@ -7047,7 +7053,7 @@ describe('probeOnboardingModal (in-page onboarding modal detection)', () => {
it('clicks a localised confirm button when the operator supplied its label', () => {
const button = el('Continuar', { button: true });
- nest(el('Novedades de WhatsApp Web'), button);
+ nest(el('Novedades de WhatsApp Web', { dialog: true }), button);
install([button]);
const result = probeOnboardingModal({
@@ -7059,6 +7065,33 @@ describe('probeOnboardingModal (in-page onboarding modal detection)', () => {
expect(button.click).toHaveBeenCalledTimes(1);
});
+ it('accepts an aria-modal container as the dialog around an operator label', () => {
+ const button = el('Continuar', { button: true });
+ nest(el('Novidades do WhatsApp Web', { ariaModal: true }), nest(el('footer'), button));
+ install([button]);
+
+ expect(probeOnboardingModal({ labels: ['Continue', 'Continuar'], headingOptionalFor: ['Continuar'] })).toEqual({
+ modalPresent: true,
+ dismissed: true,
+ });
+ expect(button.click).toHaveBeenCalledTimes(1);
+ });
+
+ // The operator label skips the heading check, so the dialog is its only anchor: the same word on a
+ // button anywhere else on the page must not be clicked, since every click counts toward the limit
+ // that moves a ready session to action_required.
+ it('does not click an operator label that sits outside any dialog', () => {
+ const button = el('Continuar', { button: true });
+ nest(el('Novedades de WhatsApp Web'), button);
+ install([button]);
+
+ expect(probeOnboardingModal({ labels: ['Continue', 'Continuar'], headingOptionalFor: ['Continuar'] })).toEqual({
+ modalPresent: false,
+ dismissed: false,
+ });
+ expect(button.click).not.toHaveBeenCalled();
+ });
+
// The loosening is scoped to the operator's own labels: the default label keeps its heading guard, so
// configuring an extra label cannot start matching stray "Continue" buttons elsewhere on the page.
it('still requires the heading for the default label even when extra labels are configured', () => {
diff --git a/src/engine/adapters/wwebjs-onboarding.ts b/src/engine/adapters/wwebjs-onboarding.ts
index e02bbbe18..8b57eac40 100644
--- a/src/engine/adapters/wwebjs-onboarding.ts
+++ b/src/engine/adapters/wwebjs-onboarding.ts
@@ -17,7 +17,8 @@ export const ONBOARDING_DEFAULT_CONTINUE_LABEL = 'Continue';
*
* Supplying labels also drops the heading requirement for THOSE labels: the English heading regex
* would reject a localised modal anyway, so requiring both would make the setting useless. That is a
- * deliberate, operator-opted-in loosening — see {@link probeOnboardingModal}.
+ * deliberate, operator-opted-in loosening, bounded by requiring the button to sit inside a visible
+ * dialog; see {@link probeOnboardingModal}.
*/
export function resolveOnboardingContinueLabels(): string[] {
const extra = (process.env.WWEBJS_ONBOARDING_CONTINUE_LABELS ?? '')
@@ -49,6 +50,8 @@ export function resolveOnboardingContinueLabels(): string[] {
* modal in Portuguese (#1679). Another language is covered by an operator-supplied label (see
* {@link resolveOnboardingContinueLabels}), which matches WITHOUT the heading check: the English
* heading would reject a localised modal regardless, so requiring both would make the setting inert.
+ * It does require a `[role="dialog"]` or `[aria-modal="true"]` ancestor, so the word is only clicked
+ * where a modal can be.
* The default `Continue` keeps the heading requirement, so the out-of-the-box false-positive surface
* is unchanged.
*/
@@ -68,8 +71,20 @@ export function probeOnboardingModal(options?: { labels?: string[]; headingOptio
const candidates = Array.from(document.querySelectorAll('button, [role="button"]'))
.map(el => ({ el, label: (el.textContent || '').trim() }))
.filter(c => isVisible(c.el) && labels.includes(c.label));
+ // An operator label carries no heading check, so it has to sit inside a dialog at least: matched
+ // page-wide, the same word on any other button would be clicked, and every click counts toward the
+ // limit that takes a ready session to action_required. Same bounded walk and dialog markers as
+ // collectDialogDiagnostics, which is where operators read the label from.
+ const insideDialog = (el: Element): boolean => {
+ let scope: Element | null = el.parentElement;
+ for (let depth = 0; depth < 12 && scope; depth++, scope = scope.parentElement) {
+ if (scope.getAttribute('role') === 'dialog' || scope.getAttribute('aria-modal') === 'true') return true;
+ }
+ return false;
+ };
for (const { el, label } of candidates.reverse()) {
if (headingOptional.has(label)) {
+ if (!insideDialog(el)) continue;
(el as HTMLElement).click();
return { modalPresent: true, dismissed: true };
}