diff --git a/package.json b/package.json index b2601c85c9..bb693d57e6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@juzi/whatsapp-web.js", - "version": "1.21.12", + "version": "1.21.13", "description": "Library for interacting with the WhatsApp Web API ", "main": "./index.js", "typings": "./index.d.ts", diff --git a/src/Client.js b/src/Client.js index b15baf0bac..73153f4168 100644 --- a/src/Client.js +++ b/src/Client.js @@ -109,6 +109,9 @@ class Client extends EventEmitter { await this.pupPage.evaluate(ExposeLegacyAuthStore, moduleRaid.toString()); } + // bridge browser log + this.page.on('console', msg => console.log('PUPPETEER PAGE LOG:', msg.text())); + const needAuthentication = await this.pupPage.evaluate(async () => { let state = window.AuthStore.AppState.state; diff --git a/src/util/Injected/Store.js b/src/util/Injected/Store.js index 2da5871d9f..63b4d4dda5 100644 --- a/src/util/Injected/Store.js +++ b/src/util/Injected/Store.js @@ -165,4 +165,23 @@ exports.ExposeStore = () => { window.injectToFunction({ module: 'WAWebE2EProtoUtils', function: 'typeAttributeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage || proto.groupInviteMessage ? 'text' : func(...args); }); + window.injectToFunction({ module: 'WAWebFileUtils', function: 'getAudioDuration'}, (func, ...args) => { + const [file] = args; + let src; + let audio; + return new Promise((resolve) => { + audio = document.createElement('audio'); + audio.addEventListener('loadeddata', resolve); + audio.addEventListener('error', (e) => {{ + console.error(e); + resolve(5); + }}); + src = URL.createObjectURL(file); + audio.src = src; + }).then(() => { + return ~~audio.seekable.end(0); + }).finally(() => { + src && URL.revokeObjectURL(src); + }); + }); };