Fix isOfficialClient (#2794)

* fix(isOfficialClient): initial commit

* fix(isOfficial): eslint my dear

* chore: eslint my dear x2

* fix(isOfficial): make code more transparent

* fix(isOfficial): missing await

* fix(isOfficial): Obfuscate set to custom seed so maintainers can verify

* feat(isOfficial): original code

* chore: eslint
This commit is contained in:
Rajeh Taher 2024-03-01 16:05:09 +02:00 • committed by GitHub
commit a339199610
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View file

@ -105,6 +105,8 @@ class Client extends EventEmitter {
if(!browserArgs.find(arg => arg.includes('--user-agent'))) {
browserArgs.push(`--user-agent=${this.options.userAgent}`);
}
// navigator.webdriver fix
browserArgs.push('--disable-blink-features=AutomationControlled');
browser = await puppeteer.launch({...puppeteerOpts, args: browserArgs});
page = (await browser.pages())[0];
@ -123,6 +125,18 @@ class Client extends EventEmitter {
await this.authStrategy.afterBrowserInitialized();
await this.initWebVersionCache();
// ocVesion (isOfficialClient patch)
await page.evaluateOnNewDocument(() => {
const originalError = Error;
//eslint-disable-next-line no-global-assign
Error = function (message) {
const error = new originalError(message);
const originalStack = error.stack;
if (error.stack.includes('moduleRaid')) error.stack = originalStack + '\n at https://web.whatsapp.com/vendors~lazy_loaded_low_priority_components.05e98054dbd60f980427.js:2:44';
return error;
};
});
await page.goto(WhatsWebURL, {
waitUntil: 'load',
timeout: 0,

View file

@ -193,6 +193,7 @@ describe('Group', function() {
describe('Leave / re-join', function () {
let code;
before(async function () {
code = await group.getInviteCode();
});