mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
searches for Chat module instead
This commit is contained in:
@@ -33,37 +33,37 @@ class Client extends EventEmitter {
|
||||
const page = await browser.newPage();
|
||||
page.setUserAgent(UserAgent);
|
||||
|
||||
if(this.options.session) {
|
||||
await page.evaluateOnNewDocument (
|
||||
if (this.options.session) {
|
||||
await page.evaluateOnNewDocument(
|
||||
session => {
|
||||
localStorage.clear();
|
||||
localStorage.setItem("WABrowserId", session.WABrowserId);
|
||||
localStorage.setItem("WASecretBundle", session.WASecretBundle);
|
||||
localStorage.setItem("WAToken1", session.WAToken1);
|
||||
localStorage.setItem("WAToken2", session.WAToken2);
|
||||
}, this.options.session);
|
||||
}, this.options.session);
|
||||
}
|
||||
|
||||
|
||||
await page.goto(WhatsWebURL);
|
||||
|
||||
const KEEP_PHONE_CONNECTED_IMG_SELECTOR = '._1wSzK';
|
||||
|
||||
if(this.options.session) {
|
||||
if (this.options.session) {
|
||||
// Check if session restore was successfull
|
||||
try {
|
||||
await page.waitForSelector(KEEP_PHONE_CONNECTED_IMG_SELECTOR, {timeout: 5000});
|
||||
} catch(err) {
|
||||
if(err.name === 'TimeoutError') {
|
||||
await page.waitForSelector(KEEP_PHONE_CONNECTED_IMG_SELECTOR, { timeout: 5000 });
|
||||
} catch (err) {
|
||||
if (err.name === 'TimeoutError') {
|
||||
this.emit(Events.AUTHENTICATION_FAILURE, 'Unable to log in. Are the session details valid?');
|
||||
browser.close();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
} else {
|
||||
// Wait for QR Code
|
||||
const QR_CONTAINER_SELECTOR = '._2d3Jz';
|
||||
const QR_VALUE_SELECTOR = '._1pw2F';
|
||||
@@ -74,16 +74,16 @@ class Client extends EventEmitter {
|
||||
this.emit(Events.QR_RECEIVED, qr);
|
||||
|
||||
// Wait for code scan
|
||||
await page.waitForSelector(KEEP_PHONE_CONNECTED_IMG_SELECTOR, {timeout: 0});
|
||||
}
|
||||
|
||||
await page.waitForSelector(KEEP_PHONE_CONNECTED_IMG_SELECTOR, { timeout: 0 });
|
||||
}
|
||||
|
||||
await page.evaluate(ExposeStore, moduleRaid.toString());
|
||||
|
||||
|
||||
// Get session tokens
|
||||
const localStorage = JSON.parse(await page.evaluate(() => {
|
||||
return JSON.stringify(window.localStorage);
|
||||
return JSON.stringify(window.localStorage);
|
||||
}));
|
||||
|
||||
|
||||
const session = {
|
||||
WABrowserId: localStorage.WABrowserId,
|
||||
WASecretBundle: localStorage.WASecretBundle,
|
||||
@@ -95,14 +95,14 @@ class Client extends EventEmitter {
|
||||
|
||||
// Check Store Injection
|
||||
await page.waitForFunction('window.Store != undefined');
|
||||
|
||||
|
||||
//Load custom serializers
|
||||
await page.evaluate(LoadCustomSerializers);
|
||||
|
||||
// Register events
|
||||
await page.exposeFunction('onAddMessageEvent', msg => {
|
||||
if (!msg.isNewMsg) return;
|
||||
|
||||
|
||||
const message = new Message(this, msg);
|
||||
this.emit(Events.MESSAGE_CREATE, message);
|
||||
|
||||
@@ -120,7 +120,7 @@ class Client extends EventEmitter {
|
||||
await page.evaluate(() => {
|
||||
Store.Msg.on('add', onAddMessageEvent);
|
||||
Store.Conn.on('change:connected', onConnectionChangedEvent);
|
||||
})
|
||||
}).catch(err => console.log(err.message));
|
||||
|
||||
this.pupBrowser = browser;
|
||||
this.pupPage = page;
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
exports.ExposeStore = (moduleRaidStr) => {
|
||||
eval("var moduleRaid = " + moduleRaidStr);
|
||||
window.mR = moduleRaid();
|
||||
window.Store = window.mR.findModule("Conn")[0].default;
|
||||
window.Store = window.mR.findModule("Chat")[1].default;
|
||||
|
||||
window.Store.genId = window.mR.findModule((module) => module.default && typeof module.default === 'function' && module.default.toString().match(/crypto/))[0].default;
|
||||
window.Store.SendMessage = window.mR.findModule("sendTextMsgToChat")[0].sendTextMsgToChat;
|
||||
}
|
||||
@@ -19,7 +20,7 @@ exports.LoadCustomSerializers = () => {
|
||||
res.isGroup = chat.isGroup;
|
||||
res.formattedTitle = chat.formattedTitle;
|
||||
|
||||
if(chat.groupMetadata) {
|
||||
if (chat.groupMetadata) {
|
||||
res.groupMetadata = chat.groupMetadata.serialize();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user