From d159e680839ae9eafdad0776dab1c1250e6adc19 Mon Sep 17 00:00:00 2001 From: Marc Nuri Date: Sat, 6 Jan 2024 08:57:27 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20latest=20Chrome=20release=20retr?= =?UTF-8?q?ieved=20from=20versionhistory.googleapis.com?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc Nuri --- src/user-agent/__tests__/index.test.js | 18 +++++++++++------- src/user-agent/index.js | 12 +++++------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/user-agent/__tests__/index.test.js b/src/user-agent/__tests__/index.test.js index 9e355aa2..d1eb4406 100644 --- a/src/user-agent/__tests__/index.test.js +++ b/src/user-agent/__tests__/index.test.js @@ -25,10 +25,12 @@ describe('User Agent module test suite', () => { describe('initBrowserVersions', () => { test('valid responses, should return a valid version for all browsers,', async () => { // Given - axios.get.mockImplementationOnce(async () => ({data: [ - {os: 'linux', versions: [{channel: 'other', version: '5uck5'}, {channel: 'stable', version: '1337'}]}, - {os: 'win'} - ]})); + axios.get.mockImplementationOnce(async () => ({data: { + releases: [ + {name: 'chrome/platforms/linux/channels/stable/versions/1337/releases/1704308709', version: '1337'}, + {name: 'chrome/platforms/linux/channels/stable/versions/1336/releases/1704308708', version: '1336'} + ] + }})); axios.get.mockImplementation(async () => ({data: { FIREFOX_DEVEDITION: '313373', LATEST_FIREFOX_VERSION: 'ff.1337', @@ -43,9 +45,11 @@ describe('User Agent module test suite', () => { }); test('invalidResponse, should return null,', async () => { // Given - axios.get.mockImplementation(async () => ({data: [ - {os: 'win'}, 'not Valid' - ]})); + axios.get.mockImplementation(async () => ({data: { + releases: [ + {os: 'win'}, 'not Valid' + ] + }})); // When await userAgent.initBrowserVersions(); // Then diff --git a/src/user-agent/index.js b/src/user-agent/index.js index cf1f8f58..846ddaad 100644 --- a/src/user-agent/index.js +++ b/src/user-agent/index.js @@ -14,7 +14,7 @@ limitations under the License. */ const axios = require('axios'); -const CHROMIUM_VERSIONS = 'https://omahaproxy.appspot.com/all.json'; +const CHROMIUM_VERSIONS = `https://versionhistory.googleapis.com/v1/chrome/platforms/linux/channels/stable/versions/all/releases?filter=endtime>${new Date().toISOString()}`; const FIREFOX_VERSIONS = 'https://product-details.mozilla.org/1.0/firefox_versions.json'; const BROWSER_VERSIONS = { @@ -28,12 +28,10 @@ const USER_AGENT_INTERCEPTOR_FILTER = { }; const latestChromium = async () => { - const {data: tags} = await axios.get(CHROMIUM_VERSIONS); - const stableVersion = tags - .filter(version => version.os === 'linux') - .flatMap(version => version.versions) - .filter(version => version.channel === 'stable'); - return stableVersion && stableVersion.length > 0 ? stableVersion[0].version : null; + const {data} = await axios.get(CHROMIUM_VERSIONS); + const stableVersion = data.releases + .flatMap(release => release.version); + return stableVersion && stableVersion.length > 0 ? stableVersion[0] : null; }; const latestFirefox = async () => {