Fix context destroyed on client initialize #3531
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Details
Catch errors during intialization ONLY if page reloading events occours
Description
in
Client.initialize()
function an handler offramenavigated
event is created to track that a page reloading is ongoing and context can be destroyed in any moment. If some error happens due toframenavigated
the flow can return normally because anotherClient.initialize()
are going to be re-executed (Client.js:339
)Related Issue(s)
closes #2056
Motivation and Context
The change is required to handle errors from context destroyed correclty during initialization without killing the process if unpredictable (by Meta) refresh happens.
Error raised on reloading when initialization is in progress:
at rewriteError (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:284:15) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async ExecutionContext._ExecutionContext_evaluate (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:227:56) at async ExecutionContext.evaluate (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:107:16) at async Client.getWWebVersion (/usr/src/app/node_modules/whatsapp-web.js/src/Client.js:811:16) at async Client.inject (/usr/src/app/node_modules/whatsapp-web.js/src/Client.js:98:25) at async Client.initialize (/usr/src/app/node_modules/whatsapp-web.js/src/Client.js:329:9)
How Has This Been Tested
My clients in production never crash anymore during initialization and connect correctrly at first run.
Environment
Types of changes
Checklist