Skip to content

fix: retrieving profile pic - #201880

Open
Karvy-Singh wants to merge 2 commits into
wwebjs:mainfrom
Karvy-Singh:main
Open

fix: retrieving profile pic#201880
Karvy-Singh wants to merge 2 commits into
wwebjs:mainfrom
Karvy-Singh:main

Conversation

@Karvy-Singh

@Karvy-Singh Karvy-Singh commented Aug 3, 2026

Copy link
Copy Markdown

Description

Fixes Client#getProfilePicUrl() after the previous WAWebContactProfilePicThumbBridge lookup stopped retrieving profile pictures correctly.

The method now:

  • Converts the contact ID using WAWebWidFactory.createWid().
  • Checks the existing WAWebCollections.ProfilePicThumb collection.
  • Fetches the profile picture model with find() when it is not already loaded.
  • Returns the profile picture URL when available, or undefined when 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 the ready event, using a contact whose profile picture was visible to the authenticated account. The method successfully returned a valid profile picture URL.

Additional validation:

  • node --check passed.
  • Prettier formatting check passed.
  • Full automated test suite was not run.

Environment

  • Machine OS: Manjaro Linux
  • Phone OS: Oxygen OS 16.0.5
  • Library Version: 1.34.7
  • WhatsApp Web Version: 2.3000.1044341106
  • Browser Type and Version: Chromium 150.0.7871.124
  • Node Version: 26.4.0

Type of Change

  • Dependency change (package changes such as removals, upgrades, or additions)
  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Non-code change (documentation, README, etc.)

Checklist

  • My code follows the style guidelines of this project.
  • All new and existing tests pass (npm test).
  • Typings (e.g. index.d.ts) have been updated if necessary.
  • Usage examples (e.g. example.js) / documentation have been updated if applicable.

Copilot AI review requested due to automatic review settings August 3, 2026 15:32
@github-actions github-actions Bot added the api changes API modifications label Aug 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 contactId into a Wid via WAWebWidFactory.createWid().
  • Look up the profile picture via WAWebCollections.ProfilePicThumb (get then find fallback).
  • 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.

Comment thread src/Client.js Outdated
Comment thread src/Client.js
Comment thread src/Client.js
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 other pupPage.evaluate calls in the codebase (which typically only swallow ServerStatusCodeError) and can make real regressions silently look like “no profile pic”. Catch the error object and only return undefined for 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 uses WAWebCollections.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#getProfilePicUrl is now documented to return Promise<string|undefined>, but the public TypeScript typings (and Contact#getProfilePicUrl docs) still indicate Promise<string>. This is a user-visible API contract mismatch that can lead to runtime undefined where 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) {

@Karvy-Singh

Karvy-Singh commented Aug 4, 2026

Copy link
Copy Markdown
Author

@BenyFilho
Would it be possible to get the API changes in upstream itself ? Many of us have been using the Library and there are a lot of functions which needs internal patching.

I personally encountered three in a project which is not even 200 lines yet.
.getchats(),.getProfilePicUrl(), .downloadMedia()
and sadly it is evident, more are to be witnessed.

I have tried to fix the profile pic in this PR,
and other two already have open PRs.

Myself and a lot others would be quite grateful if we can use the upstream instead of our patches.
Thanking you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api changes API modifications

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix getProfilePicUrl() failures caused by incompatible Chat objects from WWebJS.getChat()

2 participants