From ba6386e0aef4d9c706c3f35fbddaa3513cba88f5 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Tue, 5 Nov 2024 10:34:00 +0100 Subject: [PATCH] fix(download): fix second browser download of channels (#33429) --- packages/playwright-core/browsers.json | 6 +++++ .../src/server/registry/index.ts | 25 +++++++------------ utils/roll_browser.js | 8 ++++++ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/packages/playwright-core/browsers.json b/packages/playwright-core/browsers.json index 05c0ee8381..b01f52fbd8 100644 --- a/packages/playwright-core/browsers.json +++ b/packages/playwright-core/browsers.json @@ -7,6 +7,12 @@ "installByDefault": true, "browserVersion": "131.0.6778.24" }, + { + "name": "chromium-headless-shell", + "revision": "1146", + "installByDefault": false, + "browserVersion": "131.0.6778.24" + }, { "name": "chromium-tip-of-tree", "revision": "1274", diff --git a/packages/playwright-core/src/server/registry/index.ts b/packages/playwright-core/src/server/registry/index.ts index 2c94b7f381..bf871e63c8 100644 --- a/packages/playwright-core/src/server/registry/index.ts +++ b/packages/playwright-core/src/server/registry/index.ts @@ -352,7 +352,7 @@ export const registryDirectory = (() => { function isBrowserDirectory(browserDirectory: string): boolean { const baseName = path.basename(browserDirectory); for (const browserName of allDownloadable) { - if (baseName.startsWith(browserName + '-')) + if (baseName.startsWith(browserName.replace(/-/g, '_') + '-')) return true; } return false; @@ -406,7 +406,7 @@ export type BrowserName = 'chromium' | 'firefox' | 'webkit' | 'bidi'; type InternalTool = 'ffmpeg' | 'firefox-beta' | 'chromium-tip-of-tree' | 'chromium-headless-shell' |'android'; type BidiChannel = 'bidi-firefox-stable' | 'bidi-firefox-beta' | 'bidi-firefox-nightly' | 'bidi-chrome-canary' | 'bidi-chrome-stable' | 'bidi-chromium'; type ChromiumChannel = 'chrome' | 'chrome-beta' | 'chrome-dev' | 'chrome-canary' | 'msedge' | 'msedge-beta' | 'msedge-dev' | 'msedge-canary'; -const allDownloadable = ['chromium', 'firefox', 'webkit', 'ffmpeg', 'firefox-beta', 'chromium-tip-of-tree', 'chromium-headless-shell']; +const allDownloadable = ['android', 'chromium', 'firefox', 'webkit', 'ffmpeg', 'firefox-beta', 'chromium-tip-of-tree', 'chromium-headless-shell']; export interface Executable { type: 'browser' | 'tool' | 'channel'; @@ -489,27 +489,20 @@ export class Registry { _isHermeticInstallation: true, }); - const chromiumHeadlessShellDescriptor: BrowsersJSONDescriptor = { - name: 'chromium-headless-shell', - revision: chromium.revision, - browserVersion: chromium.browserVersion, - dir: chromium.dir.replace(/(.*)(-\d+)$/, '$1-headless-shell$2'), - installByDefault: false, - hasRevisionOverride: false, - }; - const chromiumHeadlessShellExecutable = findExecutablePath(chromiumHeadlessShellDescriptor.dir, 'chromium-headless-shell'); + const chromiumHeadlessShell = descriptors.find(d => d.name === 'chromium-headless-shell')!; + const chromiumHeadlessShellExecutable = findExecutablePath(chromiumHeadlessShell.dir, 'chromium-headless-shell'); this._executables.push({ type: 'tool', name: 'chromium-headless-shell', browserName: 'chromium', - directory: chromiumHeadlessShellDescriptor.dir, + directory: chromiumHeadlessShell.dir, executablePath: () => chromiumHeadlessShellExecutable, executablePathOrDie: (sdkLanguage: string) => executablePathOrDie('chromium-headless-shell', chromiumHeadlessShellExecutable, false, sdkLanguage), - installType: 'download-on-demand', - _validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, chromiumHeadlessShellDescriptor.dir, ['chrome-linux'], [], ['chrome-win']), - downloadURLs: this._downloadURLs(chromiumHeadlessShellDescriptor), + installType: chromiumHeadlessShell.installByDefault ? 'download-by-default' : 'download-on-demand', + _validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, chromiumHeadlessShell.dir, ['chrome-linux'], [], ['chrome-win']), + downloadURLs: this._downloadURLs(chromiumHeadlessShell), browserVersion: chromium.browserVersion, - _install: () => this._downloadExecutable(chromiumHeadlessShellDescriptor, chromiumHeadlessShellExecutable), + _install: () => this._downloadExecutable(chromiumHeadlessShell, chromiumHeadlessShellExecutable), _dependencyGroup: 'chromium', _isHermeticInstallation: true, }); diff --git a/utils/roll_browser.js b/utils/roll_browser.js index a57b4f5004..4d9167f0f7 100755 --- a/utils/roll_browser.js +++ b/utils/roll_browser.js @@ -94,6 +94,14 @@ Example: console.log('\nUpdating browser version in browsers.json...'); for (const descriptor of descriptors) descriptor.browserVersion = browserVersion; + + // 4.1 chromium-headless-shell is equal to chromium version. + if (browserName === 'chromium') { + const headlessShellBrowser = await browsersJSON.browsers.find(b => b.name === 'chromium-headless-shell'); + headlessShellBrowser.revision = revision; + headlessShellBrowser.browserVersion = browserVersion; + } + fs.writeFileSync(path.join(CORE_PATH, 'browsers.json'), JSON.stringify(browsersJSON, null, 2) + '\n'); }