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:
parent
81fd090e36
commit
ca30ac4b18
3 changed files with 37 additions and 0 deletions
11
example.js
11
example.js
|
|
@ -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
10
index.d.ts
vendored
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue