Skip to content

Commit 2b7edc8

Browse files
committed
chore: custom title for browser downloads
- `Chrome for Testing` - `Chrome Headless Shell` - `Firefox` - `Firefox Beta` - `WebKit` Example output: ``` Downloading Chrome for Testing 143.0.7499.25 (playwright chromium v1202) from https://cdn.playwright.dev/dbazure/download/playwright/builds/chromium/1202/chromium-mac-arm64.zip 160 MiB [====================] 100% 0.0s Chrome for Testing 143.0.7499.25 (playwright chromium v1202) downloaded to /Users/dgozman/Library/Caches/ms-playwright/chromium-1202 ```
1 parent 16ddf81 commit 2b7edc8

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

packages/playwright-core/browsers.json

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,43 @@
55
"name": "chromium",
66
"revision": "1202",
77
"installByDefault": true,
8-
"browserVersion": "143.0.7499.25"
8+
"browserVersion": "143.0.7499.25",
9+
"title": "Chrome for Testing"
910
},
1011
{
1112
"name": "chromium-headless-shell",
1213
"revision": "1202",
1314
"installByDefault": true,
14-
"browserVersion": "143.0.7499.25"
15+
"browserVersion": "143.0.7499.25",
16+
"title": "Chrome Headless Shell"
1517
},
1618
{
1719
"name": "chromium-tip-of-tree",
1820
"revision": "1384",
1921
"installByDefault": false,
20-
"browserVersion": "143.0.7499.25"
22+
"browserVersion": "143.0.7499.25",
23+
"title": "Chrome Canary for Testing"
2124
},
2225
{
2326
"name": "chromium-tip-of-tree-headless-shell",
2427
"revision": "1384",
2528
"installByDefault": false,
26-
"browserVersion": "143.0.7499.25"
29+
"browserVersion": "143.0.7499.25",
30+
"title": "Chrome Canary Headless Shell"
2731
},
2832
{
2933
"name": "firefox",
3034
"revision": "1497",
3135
"installByDefault": true,
32-
"browserVersion": "144.0.2"
36+
"browserVersion": "144.0.2",
37+
"title": "Firefox"
3338
},
3439
{
3540
"name": "firefox-beta",
3641
"revision": "1493",
3742
"installByDefault": false,
38-
"browserVersion": "145.0b10"
43+
"browserVersion": "145.0b10",
44+
"title": "Firefox Beta"
3945
},
4046
{
4147
"name": "webkit",
@@ -55,7 +61,8 @@
5561
"ubuntu20.04-x64": "2092",
5662
"ubuntu20.04-arm64": "2092"
5763
},
58-
"browserVersion": "26.0"
64+
"browserVersion": "26.0",
65+
"title": "WebKit"
5966
},
6067
{
6168
"name": "ffmpeg",

packages/playwright-core/src/server/registry/index.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ type BrowsersJSON = {
486486
name: string,
487487
revision: string,
488488
browserVersion?: string,
489+
title?: string,
489490
installByDefault: boolean,
490491
revisionOverrides?: {[os: string]: string},
491492
}[]
@@ -496,6 +497,7 @@ type BrowsersJSONDescriptor = {
496497
revision: string,
497498
hasRevisionOverride: boolean
498499
browserVersion?: string,
500+
title?: string,
499501
installByDefault: boolean,
500502
dir: string,
501503
};
@@ -519,6 +521,7 @@ function readDescriptors(browsersJSON: BrowsersJSON): BrowsersJSONDescriptor[] {
519521
hasRevisionOverride: !!revisionOverride,
520522
// We only put browser version for the supported operating systems.
521523
browserVersion: revisionOverride ? undefined : obj.browserVersion,
524+
title: obj['title'],
522525
installByDefault: !!obj.installByDefault,
523526
// Method `isBrowserDirectory` determines directory to be browser iff
524527
// it starts with some browser name followed by '-'. Some browser names
@@ -1247,13 +1250,7 @@ export class Registry {
12471250
logPolitely(message);
12481251
}
12491252

1250-
const displayName = descriptor.name.split('-').map(word => {
1251-
return word === 'ffmpeg' ? 'FFMPEG' : word.charAt(0).toUpperCase() + word.slice(1);
1252-
}).join(' ');
1253-
const title = descriptor.browserVersion
1254-
? `${displayName} ${descriptor.browserVersion} (playwright build v${descriptor.revision})`
1255-
: `${displayName} playwright build v${descriptor.revision}`;
1256-
1253+
const title = calculateDownloadTitle(descriptor);
12571254
const downloadFileName = `playwright-download-${descriptor.name}-${hostPlatform}-${descriptor.revision}.zip`;
12581255
// PLAYWRIGHT_DOWNLOAD_CONNECTION_TIMEOUT is a misnomer, it actually controls the socket's
12591256
// max idle timeout. Unfortunately, we cannot rename it without breaking existing user workflows.
@@ -1523,4 +1520,12 @@ function lowercaseAllKeys(json: any): any {
15231520
return result;
15241521
}
15251522

1523+
function calculateDownloadTitle(descriptor: BrowsersJSONDescriptor) {
1524+
const title = descriptor.title ?? descriptor.name.split('-').map(word => {
1525+
return word === 'ffmpeg' ? 'FFMPEG' : word.charAt(0).toUpperCase() + word.slice(1);
1526+
}).join(' ');
1527+
const version = descriptor.browserVersion ? ' ' + descriptor.browserVersion : '';
1528+
return `${title}${version} (playwright ${descriptor.name} v${descriptor.revision})`;
1529+
}
1530+
15261531
export const registry = new Registry(require('../../../browsers.json'));

tests/installation/npmTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const expect = _expect.extend({
3838
const downloaded = new Set();
3939
let index = 0;
4040
while (true) {
41-
const match = received.substring(index).match(/(chromium|chromium headless shell|firefox|webkit|winldd|ffmpeg)[\s\d\.]+\(?playwright build v\d+\)? downloaded/im);
41+
const match = received.substring(index).match(/\(playwright (chromium|chromium-headless-shell|firefox|webkit|winldd|ffmpeg) v\d+\) downloaded/im);
4242
if (!match)
4343
break;
4444
downloaded.add(match[1].replace(/\s/g, '-').toLowerCase());

0 commit comments

Comments
 (0)