fix: retrieving profile pic - #201880
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes Client#getProfilePicUrl() by switching profile photo retrieval to use WhatsApp Web internal collections/models rather than relying on WWebJS.getChat() + WAWebContactProfilePicThumbBridge.
Changes:
- Convert the provided
contactIdinto aWidviaWAWebWidFactory.createWid(). - Look up the profile picture via
WAWebCollections.ProfilePicThumb(getthenfindfallback). - Return the resolved URL (or
undefined) directly from the page context.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (3)
src/Client.js:2218
- The new
catch { return undefined; }swallows all unexpected errors from the page context (e.g., module name changes, collection API changes). This changes the method’s error contract compared to otherpupPage.evaluatecalls in the codebase (which typically only swallowServerStatusCodeError) and can make real regressions silently look like “no profile pic”. Catch the error object and only returnundefinedfor expected server/privacy failures; rethrow anything else.
return picture?.eurl;
} catch {
return undefined;
}
src/Client.js:2213
- The PR description/linked issue says the fix uses
WAWebFindChatAction.findOrCreateLatestChat()+WAWebContactProfilePicThumbBridge.requestProfilePicFromServer(), but the implementation here usesWAWebCollections.ProfilePicThumb+pictures.find(). Please align the PR description with the actual implementation, or switch the code to the documented flow so future maintainers don’t chase the wrong internal modules when this breaks again.
const wid = window
.require('WAWebWidFactory')
.createWid(contactId);
const pictures =
window.require('WAWebCollections').ProfilePicThumb;
const picture = pictures.get(wid) || (await pictures.find(wid));
src/Client.js:2205
Client#getProfilePicUrlis now documented to returnPromise<string|undefined>, but the public TypeScript typings (andContact#getProfilePicUrldocs) still indicatePromise<string>. This is a user-visible API contract mismatch that can lead to runtimeundefinedwhere callers didn’t expect it. Please update the typings/docs to match the new behavior (or keep the method returning a string consistently).
/**
* Returns the contact ID's profile picture URL, if privacy settings allow it
* @param {string} contactId the whatsapp user's ID
* @returns {Promise<string|undefined>}
*/
async getProfilePicUrl(contactId) {
|
@BenyFilho I personally encountered three in a project which is not even 200 lines yet. I have tried to fix the profile pic in this PR, Myself and a lot others would be quite grateful if we can use the upstream instead of our patches. |
Description
Fixes
Client#getProfilePicUrl()after the previousWAWebContactProfilePicThumbBridgelookup stopped retrieving profile pictures correctly.The method now:
WAWebWidFactory.createWid().WAWebCollections.ProfilePicThumbcollection.find()when it is not already loaded.undefinedwhen unavailable.Related Issue(s)
Fixes #201860
Testing Summary
Test Details
Tested manually using a locally authenticated WhatsApp client.
Called
client.getProfilePicUrl()after the client emitted thereadyevent, using a contact whose profile picture was visible to the authenticated account. The method successfully returned a valid profile picture URL.Additional validation:
node --checkpassed.Environment
Type of Change
Checklist
npm test).index.d.ts) have been updated if necessary.example.js) / documentation have been updated if applicable.