Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(reliability): WhatsApp Web version caching #1847

Merged
merged 12 commits into from
May 29, 2023

Conversation

pedroslopez
Copy link
Owner

@pedroslopez pedroslopez commented Nov 26, 2022

Description

Enables loading a specific whatsapp web version. This would mean we can target a specific whatsapp web version with a specific library version, solving our issues with having to always play catch up with WhatsApp whenever they make breaking changes.

This works by retrieving the index.html from a remote cache (which references a specific entrypoint). WhatsApp keeps old cached JS files in their CDN for a long time, so replacing the index works even after they've released new versions.

How to use

This introduces two new client options:

  • webVersion, which indicates which version of WhatsApp Web should be retrieved
  • webVersionCache, which specifies options for how the cache is set up / where to retrieve the version

There are three implementations of web version caches included:

(Default) Local

Stores the version in the local file system the first time its seen. Next time when there's an update, we'll retrieve it from the filesystem instead of using the latest whatsapp web version.

This is currently set by default so you don't need to do this, but you can explicitly configure the local cache like so:

webVersionCache: {
    type: 'local'
}

By default this is saved to the ./.wwebjs_cache dir, but you can change this with the path option.

The downside to this one is that you need to have run the client at least once for the cache to be populated (or manually grab it from somewhere else and put it in the right directory). This still means if someone happens to download an older library version that has a breaking change, or if the client isn't running on a persistent file system, we'll still fall back to the latest version and have issues.

Remote

Retrieves the version from some remote web server. This is pretty flexible and does not include a default host configured. We might revisit this later on and make this the default since it solves the issues mentioned with the Local cache.

Here's an example configuration using the wa-version archive:

webVersionCache: {
    type: 'remote',
    remotePath: 'https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/{version}.html',
},

Since this is so generic, remotePath lets you configure how the url is structured. {version} will be replaced at runtime with the requested version (the one passed in options.webVersion).

None

Disables any caching functionality. It's as if this feature never existed.

Usage:

webVersionCache: {
    type: 'none'
}

Strict mode

Both the local and remote caches have a strict: true option available that will throw an exception if the requested version can't be found in the cache. By default this is false and will fall back to the latest version.

@matricce
Copy link
Contributor

matricce commented Dec 8, 2022

When the session opened in the latest version and I switch to an older version (e.g. 2.2245.9 to 2.2244.6) a database error occurs and it goes to the QR screen, sometimes when I clear the cache before downgrading it seems to work

@pedroslopez
Copy link
Owner Author

When the session opened in the latest version and I switch to an older version (e.g. 2.2245.9 to 2.2244.6) a database error occurs and it goes to the QR screen, sometimes when I clear the cache before downgrading it seems to work

Yep, I've seen that as well. Some updates make changes to the database that can't be reversed, so downgrading will most likely not be explicitly supported. This would mostly be useful for deciding when to update and making sure that everything is functional and compatible with the new version before everyone updating.

@stale
Copy link

stale bot commented Jan 7, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 7, 2023
@pedroslopez pedroslopez removed the stale label Jan 15, 2023
@tryvin
Copy link

tryvin commented Feb 19, 2023

@pedroslopez do you need any help here?

@stale
Copy link

stale bot commented May 21, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 21, 2023
@stale stale bot closed this May 29, 2023
@pedroslopez pedroslopez reopened this May 29, 2023
@stale stale bot removed the stale label May 29, 2023
@pedroslopez pedroslopez changed the title (WIP / Proof of concept) WhatsApp Web version selection feat(reliability): WhatsApp Web version caching May 29, 2023
@pedroslopez pedroslopez marked this pull request as ready for review May 29, 2023 05:25
@pedroslopez
Copy link
Owner Author

@matricce thanks for letting me know about wa-version! Added support for it - check out the PR description for how to hook it up 😄

@pedroslopez pedroslopez merged commit 8ae0c0d into main May 29, 2023
2 checks passed
@pedroslopez pedroslopez deleted the pedroslopez/version-cache branch May 29, 2023 06:31
dlimars pushed a commit to somosversotech/whatsapp-web.js that referenced this pull request Jul 18, 2023
* feat: use specific whatsapp web version

* add constants to version updater

* configurable caches

* rename

* typings

* rm extraneous export

* missing from the rename

* rm version resolver

* match readme version

* use try-catch

* only persist if cache miss
dlimars pushed a commit to somosversotech/whatsapp-web.js that referenced this pull request Nov 7, 2023
* feat: use specific whatsapp web version

* add constants to version updater

* configurable caches

* rename

* typings

* rm extraneous export

* missing from the rename

* rm version resolver

* match readme version

* use try-catch

* only persist if cache miss
dlimars pushed a commit to somosversotech/whatsapp-web.js that referenced this pull request Nov 7, 2023
* feat: use specific whatsapp web version

* add constants to version updater

* configurable caches

* rename

* typings

* rm extraneous export

* missing from the rename

* rm version resolver

* match readme version

* use try-catch

* only persist if cache miss
Belfio pushed a commit to Belfio/whatsapp-web.js that referenced this pull request Jan 9, 2024
* feat: use specific whatsapp web version

* add constants to version updater

* configurable caches

* rename

* typings

* rm extraneous export

* missing from the rename

* rm version resolver

* match readme version

* use try-catch

* only persist if cache miss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants