fix(WEBJS): phantom AUTHENTICATED/READY on logout and onNewMessageId binding race - fix #2222
Release / WEBJS - chrome - amd64 - chrome (push) Waiting to run
Release / WEBJS - chromium - amd64 - latest (push) Waiting to run
Release / WEBJS - chromium - linux/arm64 - arm (push) Waiting to run
Release / GOWS - none - amd64 - gows (push) Waiting to run
Release / GOWS - none - linux/arm64 - gows-arm (push) Waiting to run
Release / NOWEB - none - amd64 - noweb (push) Waiting to run
Release / NOWEB - none - linux/arm64 - noweb-arm (push) Waiting to run

This commit is contained in:
devlikepro committed 2026-08-14 18:48:18 +07:00
1 parent d7fb3091a6
commit 382c1a7e94
3 files changed
+26 -11

No files matched your search

+19 -8
View File
@@ -8,6 +8,7 @@ import { TextStatus } from '@waha/structures/status.dto';
import { sleep } from '@waha/utils/promiseTimeout';
import { EventEmitter } from 'events';
import * as lodash from 'lodash';
import { Logger } from 'pino';
import { Page } from 'puppeteer';
import { Client, Events, Message as WebjsMessage } from 'whatsapp-web.js';
import { Message } from 'whatsapp-web.js/src/structures';
@@ -93,21 +94,31 @@ function extractReactionsByMessageKey(
export class WebjsClientCore extends Client {
public events = new EventEmitter();
private wpage: WPage = null;
private injecting: Promise<void> = null;
constructor(
options,
protected tags: boolean,
protected logger: Logger,
) {
super(options);
// Wait until it's READY and inject more utils
this.on(Events.AUTHENTICATED, async () => {
await this.attachCustomEventListeners();
await this.injectWaha();
});
this.on(Events.READY, async () => {
await this.attachCustomEventListeners();
await this.injectWaha();
});
// AUTHENTICATED and READY fire back to back - run one injection for both
this.on(Events.AUTHENTICATED, () => this.injectUtils());
this.on(Events.READY, () => this.injectUtils());
}
private injectUtils(): Promise<void> {
if (this.injecting) {
return this.injecting;
}
this.injecting = this.attachCustomEventListeners()
.then(() => this.injectWaha())
.catch((err) => this.logger.error(err, 'Failed to inject utils'))
.finally(() => {
this.injecting = null;
});
return this.injecting;
}
async initialize() {
+5 -1
View File
@@ -326,7 +326,11 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
const clientOptions = this.getClientOptions();
clientOptions.authStrategy = authStrategy;
this.addProxyConfig(clientOptions);
return new WebjsClientCore(clientOptions, this.getWebjsTagsFlag());
return new WebjsClientCore(
clientOptions,
this.getWebjsTagsFlag(),
this.logger,
);
}
protected getWebjsTagsFlag() {
+2 -2
View File
@@ -14350,7 +14350,7 @@ __metadata:
"whatsapp-web.js@github:devlikeapro/whatsapp-web.js#fork-main-2026-06-26":
version: 1.34.7
resolution: "whatsapp-web.js@https://github.com/devlikeapro/whatsapp-web.js.git#commit=b53e8e76b571d1987fcc07353de15ad0b45ff4e9"
resolution: "whatsapp-web.js@https://github.com/devlikeapro/whatsapp-web.js.git#commit=62174b15ce610ec545855fba8682485568dfb60f"
dependencies:
archiver: "npm:7.0.1"
fluent-ffmpeg: "npm:2.1.3"
@@ -14367,7 +14367,7 @@ __metadata:
optional: true
unzipper:
optional: true
checksum: 10/058158e942a61e8feb65a240a472352a930f1998d9a24b8de29889113c95c35f9361d2f2ce3c11806297a67e64c6a45170540164cacb72ce697986d60b40eba1
checksum: 10/5ad76a46a5897645f1cdba2a89613b8f11302d5c58af6a1a1ca588ece6ec65c98f16fd09506545f4120ed857f520dce056515dab008cf99cbe025d07e2e95515
languageName: node
linkType: hard