Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: download browsers as TAR #34033

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a9b40bd
add second branch
Skn0tt Dec 16, 2024
0b139f1
move chromium, chromium-tot, and webkit to brotli
Skn0tt Dec 16, 2024
98d6138
fix import
Skn0tt Dec 16, 2024
657e435
feat: download browsers as .tar.br
Skn0tt Dec 16, 2024
c5ab0c5
respect revisionOverrides
Skn0tt Dec 18, 2024
3b72c3b
update thirdparty
Skn0tt Dec 18, 2024
411cf29
update log line matcher
Skn0tt Dec 18, 2024
d880a22
update expected error codes
Skn0tt Dec 18, 2024
f39ae50
ffmpeg also has brotli builds now
Skn0tt Dec 18, 2024
f071337
remove conflicting tar-fs types
Skn0tt Dec 18, 2024
45b84b7
add workaround for manually-created ffmpeg archive
Skn0tt Dec 18, 2024
a497b6b
remove console statement
Skn0tt Dec 18, 2024
b048d2a
Merge branch 'main' into tar-download-3rd-party-lib
Skn0tt Dec 18, 2024
affff4d
Merge branch 'main' into tar-download-3rd-party-lib
Skn0tt Dec 19, 2024
879afb1
adapt to new ffmpeg roll
Skn0tt Dec 19, 2024
16ff2df
vendor modified tar-fs
Skn0tt Jan 6, 2025
eaf6a52
update thirdpartynotices
Skn0tt Jan 6, 2025
220e28b
reset package-lock
Skn0tt Jan 6, 2025
0ccbef1
reset package.json
Skn0tt Jan 6, 2025
30c5ec6
Merge branch 'main' into tar-download-3rd-party-lib
Skn0tt Jan 13, 2025
e2b1500
firefox and chrome-headless-shell have tar now
Skn0tt Jan 13, 2025
25494cb
reuse existing code better
Skn0tt Jan 13, 2025
2224fd2
continue using close
Skn0tt Jan 13, 2025
41a552f
move to third_party
Skn0tt Jan 13, 2025
dce95a5
add license/readme
Skn0tt Jan 13, 2025
2749367
remove getStreamError
Skn0tt Jan 13, 2025
7744cc5
add diff
Skn0tt Jan 13, 2025
c717419
fix _predestroy
Skn0tt Jan 13, 2025
a2d214f
add notices
Skn0tt Jan 13, 2025
5086a56
fix linter
Skn0tt Jan 13, 2025
e24a0d7
add deps
Skn0tt Jan 13, 2025
746bb68
Merge branch 'main' into tar-download-3rd-party-lib
Skn0tt Jan 21, 2025
c8b2ce0
revert test changes
Skn0tt Jan 21, 2025
6fb5355
fix test
Skn0tt Jan 21, 2025
3c63756
remove dead code
Skn0tt Jan 30, 2025
5c04f77
update diff
Skn0tt Jan 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion packages/playwright-core/ThirdPartyNotices.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ This project incorporates components from the projects listed below. The origina
- [email protected] (https://github.com/JoshGlazebrook/socks)
- [email protected] (https://github.com/alexei/sprintf.js)
- [email protected] (https://github.com/tapjs/stack-utils)
- tar-fs (https://github.com/mafintosh/tar-fs)
- tar-stream (https://github.com/mafintosh/tar-stream)
- [email protected] (https://github.com/npm/wrappy)
- [email protected] (https://github.com/websockets/ws)
- [email protected] (https://github.com/eemeli/yaml)
Expand Down Expand Up @@ -1112,6 +1114,58 @@ THE SOFTWARE.
=========================================
END OF [email protected] AND INFORMATION

%% tar-fs NOTICES AND INFORMATION BEGIN HERE
=========================================
The MIT License (MIT)

Copyright (c) 2014 Mathias Buus

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
=========================================
END OF tar-fs AND INFORMATION

%% tar-stream NOTICES AND INFORMATION BEGIN HERE
=========================================
The MIT License (MIT)

Copyright (c) 2014 Mathias Buus

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
=========================================
END OF tar-stream AND INFORMATION

%% [email protected] NOTICES AND INFORMATION BEGIN HERE
=========================================
The ISC License
Expand Down Expand Up @@ -1229,6 +1283,6 @@ END OF [email protected] AND INFORMATION

SUMMARY BEGIN HERE
=========================================
Total Packages: 48
Total Packages: 50
=========================================
END OF SUMMARY
4 changes: 2 additions & 2 deletions packages/playwright-core/browsers.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
"revision": "1011",
"installByDefault": true,
"revisionOverrides": {
"mac12": "1010",
"mac12-arm64": "1010"
"mac12": "1011",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the motivation for changing this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1010 doesn't have .tar.br, and 1010 is identical to 1011 in functionality

"mac12-arm64": "1011"
}
},
{
Expand Down
1 change: 1 addition & 0 deletions packages/playwright-core/src/server/DEPS.list
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
../protocol/
../utils/
../utils/isomorphic/
../utils/third_party/tar/
../utilsBundle.ts
../zipBundle.ts
./
Expand Down
373 changes: 188 additions & 185 deletions packages/playwright-core/src/server/registry/index.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@
* limitations under the License.
*/

import type { WriteStream } from 'fs';
import fs from 'fs';
import path from 'path';
import { httpRequest } from '../../utils/network';
import { ManualPromise } from '../../utils/manualPromise';
import { extract } from '../../zipBundle';
import tar from '../../utils/third_party/tar';
import { pipeline } from 'stream/promises';
import { createBrotliDecompress } from 'zlib';
import type { Writable } from 'stream';

export type DownloadParams = {
title: string;
Expand All @@ -42,7 +47,7 @@ function browserDirectoryToMarkerFilePath(browserDirectory: string): string {
return path.join(browserDirectory, 'INSTALLATION_COMPLETE');
}

function downloadFile(options: DownloadParams): Promise<void> {
function downloadFile(options: DownloadParams, file: WriteStream | Writable): Promise<void> {
let downloadedBytes = 0;
let totalBytes = 0;

Expand Down Expand Up @@ -72,7 +77,6 @@ function downloadFile(options: DownloadParams): Promise<void> {
}
totalBytes = parseInt(response.headers['content-length'] || '0', 10);
log(`-- total bytes: ${totalBytes}`);
const file = fs.createWriteStream(options.zipPath);
file.on('finish', () => {
if (downloadedBytes !== totalBytes) {
log(`-- download failed, size mismatch: ${downloadedBytes} != ${totalBytes}`);
Expand All @@ -86,7 +90,10 @@ function downloadFile(options: DownloadParams): Promise<void> {
response.pipe(file);
response.on('data', onData);
response.on('error', (error: any) => {
file.close();
if ('close' in file)
file.close();
else
file.destroy(error);
if (error?.code === 'ECONNRESET') {
log(`-- download failed, server closed connection`);
promise.reject(new Error(`Download failed: server closed connection. URL: ${options.url}`));
Expand All @@ -105,10 +112,29 @@ function downloadFile(options: DownloadParams): Promise<void> {
}

async function main(options: DownloadParams) {
await downloadFile(options);
log(`SUCCESS downloading ${options.title}`);
log(`extracting archive`);
await extract(options.zipPath, { dir: options.browserDirectory });
if (options.url.endsWith('.tar.br')) {
const decompress = createBrotliDecompress();
const extraction = pipeline(
decompress,
tar.extract(options.browserDirectory),
).catch(e => {
if (e.code === 'ERR_STREAM_PREMATURE_CLOSE') // caused by an upstream error in `downloadFile()`, let's no throw twice
return;

throw e;
});
await Promise.all([
extraction,
downloadFile(options, decompress)
]);
log(`SUCCESS downloading and extracting ${options.title}`);
} else {
const file = fs.createWriteStream(options.zipPath);
await downloadFile(options, file);
log(`SUCCESS downloading ${options.title}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should we place it before downloadFile and print "log(downloading ${options.title});"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to do that in a separate PR, but that would be a behaviour change to before. What'd be the benefit?

log(`extracting archive`);
await extract(options.zipPath, { dir: options.browserDirectory });
}
if (options.executablePath) {
log(`fixing permissions at ${options.executablePath}`);
await fs.promises.chmod(options.executablePath, 0o755);
Expand Down
21 changes: 21 additions & 0 deletions packages/playwright-core/src/utils/third_party/tar/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 Mathias Buus

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This folder contains the `index.js` file from the [tar-fs](https://github.com/mafintosh/tar-fs/commit/7ce355d649e47d0c79ec092bb926d325884916b0) and `extract.js` and `headers.js` files from [tar-stream](https://github.com/mafintosh/tar-stream/commit/126968fd3c4a39eba5f8318c255e04cedbbad176) with the modifications seen in `diff.patch`.
Loading
Loading