From b96607338a003f08e8fe12ce27c4e319b074ef01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=BC=BA=20L=E1=B4=87G=CC=B8=E1=B4=87=C9=B4D=20=E0=BC=BB?= <39593002+jtourisNS@users.noreply.github.com> Date: Sat, 5 Mar 2022 11:24:40 -0300 Subject: [PATCH] getProfilePicture Fix => Evaluation failed: Error: Comms::sendIq called before startComms (#1264) * Fix: Evaluation failed: Error: Comms::sendIq called before startComms * [Requested Changes] - Only call Wap if we're not on MD & vice-versa Co-authored-by: Joaquin Touris --- src/Client.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Client.js b/src/Client.js index 30d9ea3..30b0b0a 100644 --- a/src/Client.js +++ b/src/Client.js @@ -876,11 +876,20 @@ class Client extends EventEmitter { * @returns {Promise} */ async getProfilePicUrl(contactId) { - const profilePic = await this.pupPage.evaluate((contactId) => { - const chatWid = window.Store.WidFactory.createWid(contactId); - return window.Store.getProfilePicFull(chatWid); + const profilePic = await this.pupPage.evaluate(async contactId => { + let asyncPic; + if (window.Store.Features.features.MD_BACKEND) { + const chatWid = window.Store.WidFactory.createWid(contactId); + asyncPic = await window.Store.getProfilePicFull(chatWid).catch(() => { + return undefined; + }); + } else { + asyncPic = await window.Store.Wap.profilePicFind(contactId).catch(() => { + return undefined; + }); + } + return asyncPic; }, contactId); - return profilePic ? profilePic.eurl : undefined; }