Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: customise linked device name #3325

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +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. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The explanation and details should be either in example itself or in readme.md.
Imo, it's not a good practice to have a link to VCS (especially in github).

We've seen many github repos got removed and we'll lose important notes :)

// deviceName: 'TEST',
// browserName: 'Firefox', // valid value are: 'Chrome' | 'Firefox' | 'IE' | 'Opera' | 'Safari' | 'Edge'
puppeteer: {
// args: ['--proxy-server=proxy-server-that-requires-authentication.example.com'],
headless: false,
Expand Down
10 changes: 10 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,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
}
Expand Down
16 changes: 16 additions & 0 deletions src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
Loading