Skip to content

fix(structures): use updated loadEarlierMsgs options signature in fetchMessages#201713

Merged
BenyFilho merged 1 commit intowwebjs:mainfrom
themazim:fix/fetchmessages-options-signature
Apr 13, 2026
Merged

fix(structures): use updated loadEarlierMsgs options signature in fetchMessages#201713
BenyFilho merged 1 commit intowwebjs:mainfrom
themazim:fix/fetchmessages-options-signature

Conversation

@themazim
Copy link
Copy Markdown
Contributor

WhatsApp Web changed the signature of WAWebChatLoadMessages.loadEarlierMsgs from positional (chat, msgCollection) to an options object { chat, msgCollection, signal, threadId, trigger }.

Calling the old positional form crashes with Cannot read properties of undefined (reading 'waitForChatLoading') because the destructure reads e.chat on the first positional argument instead of treating the first argument as the chat.

Updates both Chat.fetchMessages and Channel.fetchMessages to pass the options object. No other behaviour change.

msgCollection is intentionally omitted — the loadEarlierMsgs implementation already falls back to chat.msgs when it is not provided, so passing it explicitly would be redundant.

Related Issue(s)

Fixes #201706

Testing Summary

Test Details

  1. Before the fix, chat.fetchMessages({ limit: 100 }) crashed inside the injected loadEarlierMsgs call with Cannot read properties of undefined (reading 'waitForChatLoading') as soon as the loop attempted to page earlier messages.
  2. After the fix, chat.fetchMessages({ limit: 100 }) returns without error and paginates backwards via loadEarlierMsgs until the requested limit is reached or WhatsApp Web reports no earlier messages available.
  3. channel.fetchMessages({ limit: 50 }) on a newsletter/channel returns the same corrected behaviour — no crash, correct pagination.

Environment

  • WhatsApp Web Version: 2.3000.103718033
  • Node Version: 22.14.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. (no public API change — the method signature of fetchMessages is unchanged, only its internal call to a WA Web module was corrected)
  • [] Usage examples (e.g. example.js) / documentation have been updated if applicable. (no API surface change)

WhatsApp Web changed the signature of WAWebChatLoadMessages.loadEarlierMsgs
from positional (chat, msgCollection) to an options object
{chat, msgCollection, signal, threadId, trigger}.

Calling the old positional form crashes with "Cannot read properties of
undefined (reading 'waitForChatLoading')" because the destructure reads
e.chat on the first positional argument instead of treating the first
argument as the chat.

Updates both Chat.fetchMessages and Channel.fetchMessages to pass the
options object. No other behaviour change.
@BenyFilho BenyFilho merged commit b0a4b6c into wwebjs:main Apr 13, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api changes API modifications approved Confirmed by maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: WAWebChatLoadMessages.loadEarlierMsgs throws waitForChatLoading on undefined

3 participants