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
This commit is contained in:
alechkos 2025-08-06 15:50:42 +03:00 • committed by GitHub
commit ca30ac4b18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 37 additions and 0 deletions

View file

@ -3,6 +3,17 @@ const { Client, Location, Poll, List, Buttons, LocalAuth } = require('./index');
const client = new Client({ const client = new Client({
authStrategy: new LocalAuth(), authStrategy: new LocalAuth(),
// proxyAuthentication: { username: 'username', password: 'password' }, // 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: { puppeteer: {
// args: ['--proxy-server=proxy-server-that-requires-authentication.example.com'], // args: ['--proxy-server=proxy-server-that-requires-authentication.example.com'],
headless: false, headless: false,

10
index.d.ts vendored
View file

@ -544,6 +544,16 @@ declare namespace WAWebJS {
/** Ffmpeg path to use when formatting videos to webp while sending stickers /** Ffmpeg path to use when formatting videos to webp while sending stickers
* @default 'ffmpeg' */ * @default 'ffmpeg' */
ffmpegPath?: string, 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 */ /** Object with proxy autentication requirements @default: undefined */
proxyAuthentication?: {username: string, password: string} | undefined proxyAuthentication?: {username: string, password: string} | undefined
} }

View file

@ -36,6 +36,8 @@ const {exposeFunctionIfAbsent} = require('./util/Puppeteer');
* @param {string} options.userAgent - User agent to use in 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 {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 {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. * @param {object} options.proxyAuthentication - Proxy Authentication object.
* *
* @fires Client#qr * @fires Client#qr
@ -95,6 +97,7 @@ class Client extends EventEmitter {
async inject() { async inject() {
await this.pupPage.waitForFunction('window.Debug?.VERSION != undefined', {timeout: this.options.authTimeoutMs}); 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 version = await this.getWWebVersion();
const isCometOrAbove = parseInt(version.split('.')?.[1]) >= 3000; 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 * Mark as seen for the Chat
* @param {string} chatId * @param {string} chatId