diff --git a/example.js b/example.js index f00b130..065fd12 100644 --- a/example.js +++ b/example.js @@ -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(); diff --git a/index.d.ts b/index.d.ts index 23ba35c..38d2ebb 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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 } /** diff --git a/src/Client.js b/src/Client.js index d0c949c..fef8e4c 100644 --- a/src/Client.js +++ b/src/Client.js @@ -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 @@ -102,6 +103,10 @@ class Client extends EventEmitter { browser = await puppeteer.launch({...puppeteerOpts, args: browserArgs}); 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); diff --git a/src/util/Constants.js b/src/util/Constants.js index 97512c1..aa1005d 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -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 }; /**