Skip to content

Commit

Permalink
🐛 latest Chrome release retrieved from versionhistory.googleapis.com
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Nuri <marc@marcnuri.com>
  • Loading branch information
manusa committed Jan 7, 2024
1 parent 4da7982 commit 843376d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
18 changes: 11 additions & 7 deletions src/user-agent/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down
12 changes: 5 additions & 7 deletions src/user-agent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 () => {
Expand Down

0 comments on commit 843376d

Please sign in to comment.