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

@ -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