Skip to content

Commit

Permalink
feat: update Chrome browser binaries (#9917)
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed Mar 27, 2023
1 parent 95c99e8 commit fcb233c
Show file tree
Hide file tree
Showing 16 changed files with 676 additions and 203 deletions.
13 changes: 10 additions & 3 deletions packages/browsers/src/browser-data/browser-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import * as chrome from './chrome.js';
import * as chromium from './chromium.js';
import * as firefox from './firefox.js';
import {
Browser,
Expand All @@ -26,13 +27,13 @@ import {

export const downloadUrls = {
[Browser.CHROME]: chrome.resolveDownloadUrl,
[Browser.CHROMIUM]: chrome.resolveDownloadUrl,
[Browser.CHROMIUM]: chromium.resolveDownloadUrl,
[Browser.FIREFOX]: firefox.resolveDownloadUrl,
};

export const executablePathByBrowser = {
[Browser.CHROME]: chrome.relativeExecutablePath,
[Browser.CHROMIUM]: chrome.relativeExecutablePath,
[Browser.CHROMIUM]: chromium.relativeExecutablePath,
[Browser.FIREFOX]: firefox.relativeExecutablePath,
};

Expand All @@ -50,10 +51,15 @@ export async function resolveBuildId(
return await firefox.resolveBuildId('FIREFOX_NIGHTLY');
}
case Browser.CHROME:
switch (tag as BrowserTag) {
case BrowserTag.LATEST:
// In CfT beta is the latest version.
return await chrome.resolveBuildId(platform, 'beta');
}
case Browser.CHROMIUM:
switch (tag as BrowserTag) {
case BrowserTag.LATEST:
return await chrome.resolveBuildId(platform, 'latest');
return await chromium.resolveBuildId(platform, 'latest');
}
}
// We assume the tag is the buildId if it didn't match any keywords.
Expand Down Expand Up @@ -84,6 +90,7 @@ export function resolveSystemExecutablePath(
'System browser detection is not supported for Firefox yet.'
);
case Browser.CHROME:
return chromium.resolveSystemExecutablePath(platform, channel);
case Browser.CHROMIUM:
return chrome.resolveSystemExecutablePath(platform, channel);
}
Expand Down
50 changes: 25 additions & 25 deletions packages/browsers/src/browser-data/chrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,43 @@ import {httpRequest} from '../httpUtil.js';

import {BrowserPlatform, ChromeReleaseChannel} from './types.js';

function archive(platform: BrowserPlatform, buildId: string): string {
function folder(platform: BrowserPlatform): string {
switch (platform) {
case BrowserPlatform.LINUX:
return 'chrome-linux';
return 'linux64';
case BrowserPlatform.MAC_ARM:
return 'mac-arm64';
case BrowserPlatform.MAC:
return 'chrome-mac';
return 'mac-x64';
case BrowserPlatform.WIN32:
return 'win32';
case BrowserPlatform.WIN64:
// Windows archive name changed at r591479.
return parseInt(buildId, 10) > 591479 ? 'chrome-win' : 'chrome-win32';
return 'win64';
}
}

function folder(platform: BrowserPlatform): string {
function chromiumDashPlatform(platform: BrowserPlatform): string {
switch (platform) {
case BrowserPlatform.LINUX:
return 'Linux_x64';
return 'linux';
case BrowserPlatform.MAC_ARM:
return 'Mac_Arm';
return 'mac';
case BrowserPlatform.MAC:
return 'Mac';
return 'mac';
case BrowserPlatform.WIN32:
return 'Win';
return 'win';
case BrowserPlatform.WIN64:
return 'Win_x64';
return 'win64';
}
}

export function resolveDownloadUrl(
platform: BrowserPlatform,
buildId: string,
baseUrl = 'https://storage.googleapis.com/chromium-browser-snapshots'
baseUrl = 'https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing'
): string {
return `${baseUrl}/${folder(platform)}/${buildId}/${archive(
platform,
buildId
return `${baseUrl}/${buildId}/${folder(platform)}/chrome-${folder(
platform
)}.zip`;
}

Expand All @@ -68,30 +68,29 @@ export function relativeExecutablePath(
case BrowserPlatform.MAC:
case BrowserPlatform.MAC_ARM:
return path.join(
'chrome-mac',
'Chromium.app',
'chrome-' + folder(platform),
'Google Chrome for Testing.app',
'Contents',
'MacOS',
'Chromium'
'Google Chrome for Testing'
);
case BrowserPlatform.LINUX:
return path.join('chrome-linux', 'chrome');
return path.join('chrome-linux64', 'chrome');
case BrowserPlatform.WIN32:
case BrowserPlatform.WIN64:
return path.join('chrome-win', 'chrome.exe');
return path.join('chrome-' + folder(platform), 'chrome.exe');
}
}
export async function resolveBuildId(
platform: BrowserPlatform,
// We will need it for other channels/keywords.
_channel: 'latest' = 'latest'
channel: 'beta' | 'stable' = 'beta'
): Promise<string> {
return new Promise((resolve, reject) => {
const request = httpRequest(
new URL(
`https://storage.googleapis.com/chromium-browser-snapshots/${folder(
`https://chromiumdash.appspot.com/fetch_releases?platform=${chromiumDashPlatform(
platform
)}/LAST_CHANGE`
)}&channel=${channel}`
),
'GET',
response => {
Expand All @@ -104,7 +103,8 @@ export async function resolveBuildId(
});
response.on('end', () => {
try {
return resolve(String(data));
const response = JSON.parse(String(data));
return resolve(response[0].version);
} catch {
return reject(new Error('Chrome version not found'));
}
Expand Down
121 changes: 121 additions & 0 deletions packages/browsers/src/browser-data/chromium.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/**
* Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import path from 'path';

import {httpRequest} from '../httpUtil.js';

import {BrowserPlatform} from './types.js';

export {resolveSystemExecutablePath} from './chrome.js';

function archive(platform: BrowserPlatform, buildId: string): string {
switch (platform) {
case BrowserPlatform.LINUX:
return 'chrome-linux';
case BrowserPlatform.MAC_ARM:
case BrowserPlatform.MAC:
return 'chrome-mac';
case BrowserPlatform.WIN32:
case BrowserPlatform.WIN64:
// Windows archive name changed at r591479.
return parseInt(buildId, 10) > 591479 ? 'chrome-win' : 'chrome-win32';
}
}

function folder(platform: BrowserPlatform): string {
switch (platform) {
case BrowserPlatform.LINUX:
return 'Linux_x64';
case BrowserPlatform.MAC_ARM:
return 'Mac_Arm';
case BrowserPlatform.MAC:
return 'Mac';
case BrowserPlatform.WIN32:
return 'Win';
case BrowserPlatform.WIN64:
return 'Win_x64';
}
}

export function resolveDownloadUrl(
platform: BrowserPlatform,
buildId: string,
baseUrl = 'https://storage.googleapis.com/chromium-browser-snapshots'
): string {
return `${baseUrl}/${folder(platform)}/${buildId}/${archive(
platform,
buildId
)}.zip`;
}

export function relativeExecutablePath(
platform: BrowserPlatform,
_buildId: string
): string {
switch (platform) {
case BrowserPlatform.MAC:
case BrowserPlatform.MAC_ARM:
return path.join(
'chrome-mac',
'Chromium.app',
'Contents',
'MacOS',
'Chromium'
);
case BrowserPlatform.LINUX:
return path.join('chrome-linux', 'chrome');
case BrowserPlatform.WIN32:
case BrowserPlatform.WIN64:
return path.join('chrome-win', 'chrome.exe');
}
}
export async function resolveBuildId(
platform: BrowserPlatform,
// We will need it for other channels/keywords.
_channel: 'latest' = 'latest'
): Promise<string> {
return new Promise((resolve, reject) => {
const request = httpRequest(
new URL(
`https://storage.googleapis.com/chromium-browser-snapshots/${folder(
platform
)}/LAST_CHANGE`
),
'GET',
response => {
let data = '';
if (response.statusCode && response.statusCode >= 400) {
return reject(new Error(`Got status code ${response.statusCode}`));
}
response.on('data', chunk => {
data += chunk;
});
response.on('end', () => {
try {
return resolve(String(data));
} catch {
return reject(new Error('Chrome version not found'));
}
});
},
false
);
request.on('error', err => {
reject(err);
});
});
}
2 changes: 1 addition & 1 deletion packages/browsers/src/httpUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function httpRequest(
protocol: url.protocol,
hostname: url.hostname,
port: url.port,
path: url.pathname,
path: url.pathname + url.search,
method,
headers: keepAlive ? {Connection: 'keep-alive'} : undefined,
};
Expand Down

0 comments on commit fcb233c

Please sign in to comment.