Skip to content

fix(client): invalidate stale navigation handlers - #201943

Open
kondv wants to merge 2 commits into
wwebjs:mainfrom
kondv:kondv-whatsapp-lifecycle-pr
Open

kondv wants to merge 2 commits into
wwebjs:mainfrom
kondv:kondv-whatsapp-lifecycle-pr

Conversation

@kondv

@kondv kondv commented Sep 29, 2026

Copy link
Copy Markdown

Description

Stop a navigation task from an old Client page from resuming auth setup or
starting injection after destroy/reinitialization.

The handler now captures its page and registration, checks that ownership before
each remaining pre-injection step, and is detached at destroy or initialization
start without removing listeners owned by callers. A new initialization resets
the old page's logout flag. Normal logout still runs its auth hooks and forces
reinjection on the current page; genuine initialization errors still reject.

This is a separate lifecycle follow-up, not a competing implementation of
#201893's navigation rejection handling. That PR already fixes both reproduced
context-loss crashes, including the newer-document-already-wired case. Its
current head still fails the old-logout/destroy/reinitialize continuation case.
This change adds no queue, binding-error suppression, inject_error contract,
timer polling, or initialize-failure browser cleanup.

This change invalidates remaining handler continuations; it does not cancel
auth-hook internals or an injection body that has already started. The original
navigation crash boundary remains the responsibility of #201893.

Related Issue(s)

Fixes #201941

Follow-up to merged #201653 and related to #201893. The original crash
regression evidence is recorded at
#201893 (comment).
This PR addresses the distinct stale-handler lifecycle gap. #201897 is
explicitly out of scope.

Testing Summary

Test Details

  • npm run test-single -- tests/client-navigation.js: 19 passing.
    The same final file against main 064a3d5 gives 8 passing, 11 failing.
  • Separate account-free Puppeteer fixtures ran the actual Client lifecycle on
    fresh offline Chromium pages: guards, genuine initialization rejection,
    normal logout, and old logout across full destroy/reinitialization all pass
    (4 passing). New-page navigation no longer inherits the old logout.
  • The minimal lifecycle reproduction fails on main 064a3d5 and fix(client): prevent concurrent injection crash #201893 head
    4d1f29e; auth-hook/injection counts grow from [1,1,1] to [2,2,2].
    With this change they stay [1,1,1].
  • ./node_modules/.bin/eslint src/Client.js tests/client-navigation.js: pass.
  • ./node_modules/.bin/prettier --check src/Client.js tests/client-navigation.js tests/README.md: pass.
  • node --check src/Client.js, node --check tests/client-navigation.js,
    and git diff --check: pass.
  • No build script is defined. The default npm test requires real account
    configuration and sends messages, so it was not run. No live WhatsApp
    end-to-end testing is claimed.

Environment

  • Machine OS: macOS 26.6.2
  • Phone OS: Not applicable; account-free fixtures
  • Library Version: 1.34.7, based on 064a3d5a5a3dce1281a6a12740b5a7051339d154
  • WhatsApp Web Version: Not applicable; synthetic offline fixture modules
  • Browser Type and Version: Chromium 149.0.7827.55; Puppeteer 24.38.0
  • Node Version: 22.20.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/type changes).
  • Usage examples (e.g. example.js) / documentation have been updated if applicable (tests/README.md).

The full-test checkbox is intentionally unchecked: only the account-free scope
above was run.

Girish Konda and others added 2 commits September 28, 2026 21:11
Detach the owned frame listener on destroy and reinitialization. Guard pre-injection continuations against a replaced page registration, including synchronous disconnected listeners.

Keep the navigation rejection handling proposed in wwebjs#201893 separate. Add account-free lifecycle regressions and document their runner.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Clear the previous page's logout flag when initialization starts.
Add a regression for normal navigation after destroy and reinitialize.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added docs Documentation changes api changes API modifications tests Test related labels Sep 29, 2026

This branch has not been deployed

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

Labels

api changes API modifications docs Documentation changes tests Test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stale framenavigated tasks resume on a reinitialized Client

1 participant