From 59071a07d96dd4a827d00258fb30ae23d46f47a0 Mon Sep 17 00:00:00 2001 From: alechkos <93551621+alechkos@users.noreply.github.com> Date: Fri, 4 Oct 2024 04:11:09 +0300 Subject: [PATCH 1/5] feat: add functionality for setting device and browser names --- src/Client.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Client.js b/src/Client.js index c5a6c3bfd3..1f31ac6f62 100644 --- a/src/Client.js +++ b/src/Client.js @@ -95,6 +95,7 @@ class Client extends EventEmitter { async inject() { await this.pupPage.waitForFunction('window.Debug?.VERSION != undefined', {timeout: this.options.authTimeoutMs}); + await this.setDeviceName(this.options.deviceName, this.options.browserName); const version = await this.getWWebVersion(); const isCometOrAbove = parseInt(version.split('.')?.[1]) >= 3000; @@ -813,6 +814,19 @@ class Client extends EventEmitter { }); } + async setDeviceName(deviceName, browserName) { + (deviceName || browserName) && await this.pupPage.evaluate((deviceName, browserName) => { + const func = window.require('WAWebMiscBrowserUtils').info; + window.require('WAWebMiscBrowserUtils').info = () => { + return { + ...func(), + ...(deviceName ? { os: deviceName } : {}), + ...(browserName ? { name: browserName } : {}) + }; + }; + }, deviceName, browserName); + } + /** * Mark as seen for the Chat * @param {string} chatId From 0ea0b11555c7a67e935323b62c3c28a797cb8b31 Mon Sep 17 00:00:00 2001 From: alechkos <93551621+alechkos@users.noreply.github.com> Date: Fri, 4 Oct 2024 04:11:27 +0300 Subject: [PATCH 2/5] feat: add usage example --- example.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/example.js b/example.js index 3334e5b6a2..5e2ef8a903 100644 --- a/example.js +++ b/example.js @@ -3,6 +3,8 @@ const { Client, Location, Poll, List, Buttons, LocalAuth } = require('./index'); const client = new Client({ authStrategy: new LocalAuth(), // proxyAuthentication: { username: 'username', password: 'password' }, + // deviceName: 'TEST', + // browserName: 'Firefox', puppeteer: { // args: ['--proxy-server=proxy-server-that-requires-authentication.example.com'], headless: false, From b9f1a055d2751219752c579525ff207817c04b59 Mon Sep 17 00:00:00 2001 From: alechkos <93551621+alechkos@users.noreply.github.com> Date: Fri, 4 Oct 2024 04:11:27 +0300 Subject: [PATCH 3/5] feat: add usage example --- example.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/example.js b/example.js index 5e2ef8a903..5967215255 100644 --- a/example.js +++ b/example.js @@ -3,8 +3,9 @@ const { Client, Location, Poll, List, Buttons, LocalAuth } = require('./index'); const client = new Client({ authStrategy: new LocalAuth(), // proxyAuthentication: { username: 'username', password: 'password' }, + /** Check https://github.com/pedroslopez/whatsapp-web.js/pull/3325 for full explanation. */ // deviceName: 'TEST', - // browserName: 'Firefox', + // browserName: 'Firefox', // valid value are: 'Chrome' | 'Firefox' | 'IE' | 'Opera' | 'Safari' | 'Edge' puppeteer: { // args: ['--proxy-server=proxy-server-that-requires-authentication.example.com'], headless: false, From 1ca5ab0968da3130a1d5a2e503e38c7ad0783889 Mon Sep 17 00:00:00 2001 From: alechkos <93551621+alechkos@users.noreply.github.com> Date: Fri, 4 Oct 2024 18:06:44 +0300 Subject: [PATCH 4/5] docs: add docs for new functionality --- index.d.ts | 7 +++++++ src/Client.js | 2 ++ 2 files changed, 9 insertions(+) diff --git a/index.d.ts b/index.d.ts index bd75dbf96b..406488c66d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -483,6 +483,13 @@ declare namespace WAWebJS { /** Ffmpeg path to use when formatting videos to webp while sending stickers * @default 'ffmpeg' */ ffmpegPath?: string, + /** Sets the device name of a current linked device., i.e.: 'TEST' */ + deviceName?: string, + /** + * Sets the browser name of a current linked device, i.e.: 'Firefox'. + * Valid value are: 'Chrome' | 'Firefox' | 'IE' | 'Opera' | 'Safari' | 'Edge' + */ + browserName?: string, /** Object with proxy autentication requirements @default: undefined */ proxyAuthentication?: {username: string, password: string} | undefined } diff --git a/src/Client.js b/src/Client.js index 1f31ac6f62..5541ce502f 100644 --- a/src/Client.js +++ b/src/Client.js @@ -36,6 +36,8 @@ const {exposeFunctionIfAbsent} = require('./util/Puppeteer'); * @param {string} options.userAgent - User agent to use in puppeteer * @param {string} options.ffmpegPath - Ffmpeg path to use when formatting videos to webp while sending stickers * @param {boolean} options.bypassCSP - Sets bypassing of page's Content-Security-Policy. + * @param {string} options.deviceName - Sets the device name of a current linked device., i.e.: 'TEST'. + * @param {string} options.browserName - Sets the browser name of a current linked device, i.e.: 'Firefox'. * @param {object} options.proxyAuthentication - Proxy Authentication object. * * @fires Client#qr From 72820ff6a4eb3cbe805998deb628e9a80dc8b8d4 Mon Sep 17 00:00:00 2001 From: alechkos <93551621+alechkos@users.noreply.github.com> Date: Fri, 4 Oct 2024 18:12:04 +0300 Subject: [PATCH 5/5] docs: add missing property --- index.d.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.d.ts b/index.d.ts index 406488c66d..5d4ce8d92d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -483,6 +483,9 @@ declare namespace WAWebJS { /** Ffmpeg path to use when formatting videos to webp while sending stickers * @default 'ffmpeg' */ ffmpegPath?: string, + /** Sets bypassing of page's Content-Security-Policy + * @default false */ + bypassCSP?: boolean, /** Sets the device name of a current linked device., i.e.: 'TEST' */ deviceName?: string, /**