Skip to content

Conversation

@IsmailKhCM
Copy link

Description

This PR fixes an issue where message events would not fire after closing and reopening the browser with a saved session. The issue was caused by the crypto store and message handling pipeline not being properly reinitialized after session restoration.

Related Issue(s)

Motivation and Context

When using saved sessions (LocalAuth/RemoteAuth), message events would stop working after closing and reopening the browser. This was due to the crypto store and message handling pipeline not being properly reinitialized. This fix ensures that messages continue to be processed correctly after session restoration.

How Has This Been Tested

  • Created automated test in tests/session_restore.js
  • Manually tested with session restoration scenarios
  • Verified message events fire correctly after browser restart
  • Confirmed both plain text and media messages work
  • Tested with multiple session restores in sequence

Environment

  • Machine OS: macOS 23.5.0
  • Phone OS: Latest iOS/Android
  • Library Version: 1.26.1-alpha.3
  • WhatsApp Web Version: 2.3000.1017054665
  • Puppeteer Version: 18.2.1
  • Browser Type and Version: Chrome (latest)
  • Node Version: v23.7.0

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • My code follows the code style of this project.
  • I have updated the documentation accordingly (index.d.ts).
  • I have updated the usage example accordingly (example.js)
This commit adds a reinitializeCryptoStore method to properly reinitialize the crypto store and message handling pipeline after session restoration. This fixes an issue where message events would not fire after closing and reopening the browser with a saved session.

Changes:\n- Added reinitializeCryptoStore method to Client class\n- Added TypeScript definitions for the new method\n- Added proper reinitialization of message event handlers\n- Forces immediate decryption attempt for ciphertext messages

Testing:\n- Manually tested with session restoration\n- Verified message events fire correctly after browser restart\n- Confirmed both plain text and media messages work
@raphazappa
Copy link

Solved my problems over here. Works :D

@laohanme
Copy link

need this, how i apply this currently?

@raphazappa
Copy link

need this, how i apply this currently?

I've simply installed using:

npm install github:IsmailKhCM/whatsapp-web.js#fix/message-events-after-session-restore

@shirser121
Copy link
Collaborator

Need to check if this solve the problem of session broken in remote auth

@tuyuribr
Copy link
Collaborator

Is this still usefull ?
Is just some rare use case ?

@khairul-hotakdev
Copy link

Is this still usefull ? Is just some rare use case ?

its not rare. happen often

@tuyuribr tuyuribr added the help wanted Extra attention is needed label Nov 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted Extra attention is needed

8 participants