From ca30ac4b187c040f5b7c4b42b408a07ae2e87a41 Mon Sep 17 00:00:00 2001 From: alechkos <93551621+alechkos@users.noreply.github.com> Date: Wed, 6 Aug 2025 15:50:42 +0300 Subject: [PATCH] feat: customise linked device name (#3325) * feat: add functionality for setting device and browser names * feat: add usage example * feat: add usage example * docs: add docs for new functionality * docs: add missing property * docs: supplement the implementation documentation --- example.js | 11 +++++++++++ index.d.ts | 10 ++++++++++ src/Client.js | 16 ++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/example.js b/example.js index 6f6a327..42c1e27 100644 --- a/example.js +++ b/example.js @@ -3,6 +3,17 @@ const { Client, Location, Poll, List, Buttons, LocalAuth } = require('./index'); const client = new Client({ authStrategy: new LocalAuth(), // proxyAuthentication: { username: 'username', password: 'password' }, + /** + * This option changes the browser name from defined in user agent to custom. + */ + // deviceName: 'Your custom name', + /** + * This option changes browser type from defined in user agent to yours. It affects the browser icon + * that is displayed in 'linked devices' section. + * Valid value are: 'Chrome' | 'Firefox' | 'IE' | 'Opera' | 'Safari' | 'Edge'. + * If another value is provided, the browser icon in 'linked devices' section will be gray. + */ + // browserName: 'Firefox', puppeteer: { // args: ['--proxy-server=proxy-server-that-requires-authentication.example.com'], headless: false, diff --git a/index.d.ts b/index.d.ts index 7d6b891..2908b01 100644 --- a/index.d.ts +++ b/index.d.ts @@ -544,6 +544,16 @@ 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, + /** + * 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 c51b176..ec8d1f6 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 @@ -95,6 +97,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 +816,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