@open-wa/wa-automate 4.23.16 → 4.23.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api/Client.js
CHANGED
@@ -355,7 +355,8 @@ class Client {
|
|
355
355
|
const START_TIME = Date.now();
|
356
356
|
spinner.info("Opening session in new tab");
|
357
357
|
const newTab = yield this._page.browser().newPage();
|
358
|
-
yield
|
358
|
+
yield browser_1.initPage(this.getSessionId(), this._createConfig, this._createConfig.customUserAgent, spinner, newTab, true);
|
359
|
+
// await newTab.goto(puppeteerConfig.WAUrl);
|
359
360
|
//Two promises. One that closes the previous page, one that sets up the new page
|
360
361
|
const closePageOnConflict = () => __awaiter(this, void 0, void 0, function* () {
|
361
362
|
const useHere = yield this._page.evaluate(() => WAPI.getUseHereString());
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Page } from 'puppeteer';
|
2
2
|
import { Spin } from './events';
|
3
3
|
import { ConfigObject } from '../api/model';
|
4
|
-
export declare function initPage(sessionId?: string, config?: ConfigObject, customUserAgent?: string, spinner?: Spin): Promise<Page>;
|
4
|
+
export declare function initPage(sessionId?: string, config?: ConfigObject, customUserAgent?: string, spinner?: Spin, _page?: Page, skipAuth?: boolean): Promise<Page>;
|
5
5
|
export declare const deleteSessionData: (config: ConfigObject) => boolean;
|
6
6
|
export declare const getSessionDataFilePath: (sessionId: string, config: ConfigObject) => string | boolean;
|
7
7
|
export declare const addScript: (page: Page, js: string) => Promise<unknown>;
|
@@ -42,7 +42,7 @@ const pico_s3_1 = require("pico-s3");
|
|
42
42
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
43
43
|
const puppeteer = require('puppeteer-extra');
|
44
44
|
let browser;
|
45
|
-
function initPage(sessionId, config, customUserAgent, spinner) {
|
45
|
+
function initPage(sessionId, config, customUserAgent, spinner, _page, skipAuth) {
|
46
46
|
var _a, _b, _c, _d, _e;
|
47
47
|
return __awaiter(this, void 0, void 0, function* () {
|
48
48
|
const setupPromises = [];
|
@@ -52,10 +52,13 @@ function initPage(sessionId, config, customUserAgent, spinner) {
|
|
52
52
|
const { default: stealth } = yield Promise.resolve().then(() => __importStar(require('puppeteer-extra-plugin-stealth')));
|
53
53
|
puppeteer.use(stealth());
|
54
54
|
}
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
let waPage = _page;
|
56
|
+
if (!waPage) {
|
57
|
+
spinner === null || spinner === void 0 ? void 0 : spinner.info('Launching Browser');
|
58
|
+
browser = yield initBrowser(sessionId, config);
|
59
|
+
waPage = yield getWAPage(browser);
|
60
|
+
}
|
61
|
+
spinner === null || spinner === void 0 ? void 0 : spinner.info('Setting Up Page');
|
59
62
|
if (config === null || config === void 0 ? void 0 : config.proxyServerCredentials) {
|
60
63
|
yield waPage.authenticate(config.proxyServerCredentials);
|
61
64
|
}
|
@@ -115,40 +118,51 @@ function initPage(sessionId, config, customUserAgent, spinner) {
|
|
115
118
|
request.continue();
|
116
119
|
}));
|
117
120
|
}
|
118
|
-
|
119
|
-
|
120
|
-
if (!sessionjson && sessionjson !== "" && config.sessionDataBucketAuth) {
|
121
|
-
try {
|
122
|
-
spinner === null || spinner === void 0 ? void 0 : spinner.info('Unable to find session data file locally, attempting to find session data in cloud storage..');
|
123
|
-
sessionjson = JSON.parse(Buffer.from(yield pico_s3_1.getTextFile(Object.assign(Object.assign({ directory: '_sessionData' }, JSON.parse(Buffer.from(config.sessionDataBucketAuth, 'base64').toString('ascii'))), { filename: `${config.sessionId || 'session'}.data.json` })), 'base64').toString('ascii'));
|
124
|
-
spinner === null || spinner === void 0 ? void 0 : spinner.succeed('Successfully downloaded session data file from cloud storage!');
|
125
|
-
}
|
126
|
-
catch (error) {
|
127
|
-
spinner === null || spinner === void 0 ? void 0 : spinner.fail(`${error instanceof pico_s3_1.FileNotFoundError ? 'The session data file was not found in the cloud storage bucket' : 'Something went wrong while fetching session data from cloud storage bucket'}. Continuing...`);
|
128
|
-
}
|
129
|
-
}
|
130
|
-
if (sessionjson) {
|
131
|
-
spinner === null || spinner === void 0 ? void 0 : spinner.info(config.multiDevice ? "multi-device enabled. Session data skipped..." : 'Existing session data detected. Injecting...');
|
132
|
-
if (!(config === null || config === void 0 ? void 0 : config.multiDevice))
|
133
|
-
yield waPage.evaluateOnNewDocument(session => {
|
134
|
-
localStorage.clear();
|
135
|
-
Object.keys(session).forEach(key => localStorage.setItem(key, session[key]));
|
136
|
-
}, sessionjson);
|
137
|
-
spinner === null || spinner === void 0 ? void 0 : spinner.succeed('Existing session data injected');
|
121
|
+
if (skipAuth) {
|
122
|
+
spinner.info("Skipping Authentication");
|
138
123
|
}
|
139
124
|
else {
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
}
|
125
|
+
/**
|
126
|
+
* AUTH
|
127
|
+
*/
|
128
|
+
spinner === null || spinner === void 0 ? void 0 : spinner.info('Loading session data');
|
129
|
+
let sessionjson = getSessionDataFromFile(sessionId, config, spinner);
|
130
|
+
if (!sessionjson && sessionjson !== "" && config.sessionDataBucketAuth) {
|
131
|
+
try {
|
132
|
+
spinner === null || spinner === void 0 ? void 0 : spinner.info('Unable to find session data file locally, attempting to find session data in cloud storage..');
|
133
|
+
sessionjson = JSON.parse(Buffer.from(yield pico_s3_1.getTextFile(Object.assign(Object.assign({ directory: '_sessionData' }, JSON.parse(Buffer.from(config.sessionDataBucketAuth, 'base64').toString('ascii'))), { filename: `${config.sessionId || 'session'}.data.json` })), 'base64').toString('ascii'));
|
134
|
+
spinner === null || spinner === void 0 ? void 0 : spinner.succeed('Successfully downloaded session data file from cloud storage!');
|
135
|
+
}
|
136
|
+
catch (error) {
|
137
|
+
spinner === null || spinner === void 0 ? void 0 : spinner.fail(`${error instanceof pico_s3_1.FileNotFoundError ? 'The session data file was not found in the cloud storage bucket' : 'Something went wrong while fetching session data from cloud storage bucket'}. Continuing...`);
|
138
|
+
}
|
139
|
+
}
|
140
|
+
if (sessionjson) {
|
141
|
+
spinner === null || spinner === void 0 ? void 0 : spinner.info(config.multiDevice ? "multi-device enabled. Session data skipped..." : 'Existing session data detected. Injecting...');
|
142
|
+
if (!(config === null || config === void 0 ? void 0 : config.multiDevice))
|
143
|
+
yield waPage.evaluateOnNewDocument(session => {
|
144
|
+
localStorage.clear();
|
145
|
+
Object.keys(session).forEach(key => localStorage.setItem(key, session[key]));
|
146
|
+
}, sessionjson);
|
147
|
+
spinner === null || spinner === void 0 ? void 0 : spinner.succeed('Existing session data injected');
|
148
|
+
}
|
149
|
+
else {
|
150
|
+
if (config === null || config === void 0 ? void 0 : config.multiDevice) {
|
151
|
+
spinner === null || spinner === void 0 ? void 0 : spinner.info("No session data detected. Opting in for MD.");
|
152
|
+
spinner === null || spinner === void 0 ? void 0 : spinner.info("Make sure to keep the session alive for at least 5 minutes after scanning the QR code before trying to restart a session!!");
|
153
|
+
yield waPage.evaluateOnNewDocument(session => {
|
154
|
+
localStorage.clear();
|
155
|
+
Object.keys(session).forEach(key => localStorage.setItem(key, session[key]));
|
156
|
+
}, {
|
157
|
+
"md-opted-in": "true",
|
158
|
+
"MdUpgradeWamFlag": "true",
|
159
|
+
"remember-me": "true"
|
160
|
+
});
|
161
|
+
}
|
151
162
|
}
|
163
|
+
/**
|
164
|
+
* END AUTH
|
165
|
+
*/
|
152
166
|
}
|
153
167
|
if ((config === null || config === void 0 ? void 0 : config.proxyServerCredentials) && !(config === null || config === void 0 ? void 0 : config.useNativeProxy)) {
|
154
168
|
yield proxy(waPage, proxyAddr);
|
package/package.json
CHANGED