fix: change the logic of wweb version retrieving (#3299)

* fix: change the logic of wweb version retrieving

* refactor: change the strategy of wweb version retrieving
This commit is contained in:
alechkos 2024-10-04 07:21:07 +03:00 • committed by GitHub
commit 17d63a53fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,12 +1,69 @@
#!/usr/bin/env node
const fs = require('fs');
const fetch = require('node-fetch');
const puppeteer = require('puppeteer');
const getLatestVersion = async (currentVersion) => {
const res = await fetch(`https://web.whatsapp.com/check-update?version=${currentVersion}&platform=web`);
const data = await res.json();
return data.currentVersion;
const args = [
'--autoplay-policy=user-gesture-required',
'--disable-background-networking',
'--disable-background-timer-throttling',
'--disable-backgrounding-occluded-windows',
'--disable-breakpad',
'--disable-client-side-phishing-detection',
'--disable-component-update',
'--disable-default-apps',
'--disable-dev-shm-usage',
'--disable-domain-reliability',
'--disable-extensions',
'--disable-features=AudioServiceOutOfProcess',
'--disable-hang-monitor',
'--disable-ipc-flooding-protection',
'--disable-notifications',
'--disable-offer-store-unmasked-wallet-cards',
'--disable-popup-blocking',
'--disable-print-preview',
'--disable-prompt-on-repost',
'--disable-renderer-backgrounding',
'--disable-speech-api',
'--disable-sync',
'--disable-gpu',
'--disable-accelerated-2d-canvas',
'--hide-scrollbars',
'--ignore-gpu-blacklist',
'--metrics-recording-only',
'--mute-audio',
'--no-default-browser-check',
'--no-first-run',
'--no-pings',
'--no-zygote',
'--password-store=basic',
'--use-gl=swiftshader',
'--use-mock-keychain',
'--disable-setuid-sandbox',
'--no-sandbox',
'--disable-blink-features=AutomationControlled',
'--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36'
];
const getLatestVersion = async () => {
const browser = await puppeteer.launch({
args: args
});
const page = await browser.newPage();
await page.goto('https://web.whatsapp.com', {
waitUntil: 'load',
timeout: 0,
referer: 'https://whatsapp.com/',
});
await page.waitForFunction(() => window.require && window.require('WAWebBuildConstants'));
const version = await page.evaluate(() => {
return window.require('WAWebBuildConstants').VERSION_STR;
});
await browser.close();
return version;
};
const getCurrentVersion = () => {
@ -40,12 +97,12 @@ const updateVersion = async (oldVersion, newVersion) => {
(async () => {
const currentVersion = getCurrentVersion();
const version = await getLatestVersion(currentVersion);
const version = (await getLatestVersion()) ?? currentVersion;
console.log(`Current version: ${currentVersion}`);
console.log(`Latest version: ${version}`);
if(currentVersion !== version) {
if (currentVersion !== version) {
console.log('Updating files...');
await updateVersion(currentVersion, version);
console.log('Updated!');