feat: Optional proxy autentication (#2143)

This commit is contained in:
Pierluca Lino 2023-04-20 17:19:57 +02:00 • committed by GitHub
commit d8fd457914
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 3 deletions

View file

@ -2,7 +2,11 @@ const { Client, Location, List, Buttons, LocalAuth } = require('./index');
const client = new Client({
authStrategy: new LocalAuth(),
puppeteer: { headless: false }
// proxyAuthentication: { username: 'username', password: 'password' },
puppeteer: {
// args: ['--proxy-server=proxy-server-that-requires-authentication.example.com'],
headless: false
}
});
client.initialize();

4
index.d.ts vendored
View file

@ -387,7 +387,9 @@ declare namespace WAWebJS {
userAgent?: string
/** Ffmpeg path to use when formating videos to webp while sending stickers
* @default 'ffmpeg' */
ffmpegPath?: string
ffmpegPath?: string,
/** Object with proxy autentication requirements @default: undefined */
proxyAuthentication?: {username: string, password: string} | undefined
}
/**

View file

@ -29,6 +29,7 @@ const NoAuth = require('./authStrategies/NoAuth');
* @param {string} options.userAgent - User agent to use in puppeteer
* @param {string} options.ffmpegPath - Ffmpeg path to use when formating videos to webp while sending stickers
* @param {boolean} options.bypassCSP - Sets bypassing of page's Content-Security-Policy.
* @param {object} options.proxyAuthentication - Proxy Authentication object.
*
* @fires Client#qr
* @fires Client#authenticated
@ -103,6 +104,10 @@ class Client extends EventEmitter {
page = (await browser.pages())[0];
}
if (this.options.proxyAuthentication !== undefined) {
await page.authenticate(this.options.proxyAuthentication);
}
await page.setUserAgent(this.options.userAgent);
if (this.options.bypassCSP) await page.setBypassCSP(true);

View file

@ -13,7 +13,8 @@ exports.DefaultOptions = {
takeoverTimeoutMs: 0,
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36',
ffmpegPath: 'ffmpeg',
bypassCSP: false
bypassCSP: false,
proxyAuthentication: undefined
};
/**