@@ -21,38 +21,46 @@ import * as NodeCrypto from "node:crypto";
2121import * as ServerConfig from "../config.ts" ;
2222import { openZipArchive } from "../zipArchive.ts" ;
2323
24- // Update the version, sizes and hashes from each chrome-headless-shell zip listed at
24+ // Update from each `chrome` zip (full Chrome: only it can capture a tab for recordings) listed at
2525// https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json
26- // Never pin below 156.0.8078.70: the shell has no CRLSet and older SPKI blocklists trust
27- // compromised eMudhra intermediates (crrev.com/c/8627687).
26+ // Never pin below 156.0.8078.70: Chrome for Testing has no CRLSet and older SPKI blocklists
27+ // trust compromised eMudhra intermediates (crrev.com/c/8627687).
2828const VERSION = "156.0.8078.70" ;
2929const ARCHIVES = {
3030 linux64 : {
31- bytes : 126_646_931 ,
32- sha256 : "a313da592261ff1e342c1e507d315f25b1809006c0508f77ce86151d464d4ccb " ,
31+ bytes : 201_035_256 ,
32+ sha256 : "baac330433bb105012b7429ad77d4ba3d4ec3768810008ce9257d5d930c1b0cd " ,
3333 } ,
3434 "linux-arm64" : {
35- bytes : 126_749_876 ,
36- sha256 : "dca11213d2e0b1db52141edd9f92ec423fd52ca25715846790d84fa1d5d16e8a " ,
35+ bytes : 200_845_435 ,
36+ sha256 : "46dce94a0790d177927044e83ee7e0f571bc22e90e6fafe21fce5c1e248bc865 " ,
3737 } ,
3838 "mac-arm64" : {
39- bytes : 103_901_293 ,
40- sha256 : "1f848385611f2e58122e68969489712661880fc9a92c9dd20428099f9998ba7b " ,
39+ bytes : 194_910_526 ,
40+ sha256 : "1070e2acc6fec1b80aac9215c9b83a381334a8c556df941e5146efb816121adb " ,
4141 } ,
4242 "mac-x64" : {
43- bytes : 109_387_968 ,
44- sha256 : "ab4cc2949f88439e2241b2712c49268f24982f2d25af87960466cc22bdc2e6e1 " ,
43+ bytes : 205_543_880 ,
44+ sha256 : "3218f6e802588632f2f8055b90035b306cad48874daf6067330e0f012afdb7ab " ,
4545 } ,
4646 win32 : {
47- bytes : 119_029_359 ,
48- sha256 : "37dc9a03f37fd79637fec9f26042bf32f04cfe5b83749d980eb1e7d1a429d47c " ,
47+ bytes : 188_579_460 ,
48+ sha256 : "853955e981b07b8c44dfc77e658f6bfc806868a74176a44900aecda65ea4c26e " ,
4949 } ,
5050 win64 : {
51- bytes : 126_214_071 ,
52- sha256 : "41c6aa97046d05d015b817a95f7b1512c3a1a41b18364f8da46478ae520400b1 " ,
51+ bytes : 209_092_934 ,
52+ sha256 : "8ab65752ca6106bb8a5bf3afaa710ab4f62a57c27ed39db4977422c929fce0b3 " ,
5353 } ,
5454} as const ;
5555
56+ /** The browser's executable inside the archive's top directory. */
57+ export const executableName = ( platform : NodeJS . Platform ) =>
58+ platform === "win32"
59+ ? "chrome.exe"
60+ : platform === "darwin"
61+ ? "Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing"
62+ : "chrome" ;
63+
5664const chromePlatform = ( platform : NodeJS . Platform , arch : NodeJS . Architecture ) => {
5765 switch ( platform ) {
5866 case "linux" :
@@ -85,7 +93,7 @@ const previewBrowserRelease = (
8593 : {
8694 version : VERSION ,
8795 platform : chrome ,
88- url : `https://storage.googleapis.com/chrome-for-testing-public/${ VERSION } /${ chrome } /chrome-headless-shell- ${ chrome } .zip` ,
96+ url : `https://storage.googleapis.com/chrome-for-testing-public/${ VERSION } /${ chrome } /chrome-${ chrome } .zip` ,
8997 ...ARCHIVES [ chrome ] ,
9098 } ;
9199} ;
@@ -119,7 +127,7 @@ export class PreviewBrowserUnsupportedError extends Schema.TaggedError<PreviewBr
119127 { platform : Schema . String , arch : Schema . String } ,
120128) {
121129 override get message ( ) : string {
122- return `T3's headless browser is not available on ${ this . platform } -${ this . arch } : Chrome for Testing has no headless shell for it.` ;
130+ return `T3's headless browser is not available on ${ this . platform } -${ this . arch } : Chrome for Testing has no build for it.` ;
123131 }
124132}
125133
@@ -170,24 +178,23 @@ export const makePreviewBrowser = Effect.fn("PreviewBrowser.make")(function* (
170178 const release =
171179 options . release === undefined ? previewBrowserRelease ( platform , arch ) : options . release ;
172180 const wait = options . wait ?? "45 seconds" ;
181+ const toolsDir = path . join ( options . baseDir , "tools" ) ;
173182 const installRoot = path . join (
174- options . baseDir ,
175- "tools" ,
176- "chrome-headless-shell" ,
183+ toolsDir ,
184+ "chrome-for-testing" ,
177185 release ?. platform ?? `${ platform } -${ arch } ` ,
178186 ) ;
179- const executableName =
180- platform === "win32" ? "chrome-headless-shell.exe" : "chrome-headless-shell" ;
187+ const binary = executableName ( platform ) ;
181188 const gate = yield * Semaphore . make ( 1 ) ;
182189 let state : InstallState = { _tag : "idle" } ;
183190 const progress = { downloadedBytes : 0 , unpacking : false } ;
184191
185192 const installedExecutable = ( release : PreviewBrowserRelease ) => {
186- const executable = path . join ( installRoot , release . version , executableName ) ;
187- return fs . stat ( executable ) . pipe (
193+ const installed = path . join ( installRoot , release . version , binary ) ;
194+ return fs . stat ( installed ) . pipe (
188195 Effect . map ( ( info ) =>
189196 info . type === "File" && ( platform === "win32" || ( info . mode & 0o111 ) !== 0 )
190- ? Option . some ( executable )
197+ ? Option . some ( installed )
191198 : Option . none < string > ( ) ,
192199 ) ,
193200 Effect . orElseSucceed ( ( ) => Option . none < string > ( ) ) ,
@@ -251,7 +258,7 @@ export const makePreviewBrowser = Effect.fn("PreviewBrowser.make")(function* (
251258 const unsafe = new PreviewBrowserInstallError ( {
252259 detail : "The archive contains an unexpected or unsafe entry." ,
253260 } ) ;
254- const root = `chrome-headless-shell- ${ release . platform } /` ;
261+ const root = `chrome-${ release . platform } /` ;
255262 yield * fs . makeDirectory ( destination ) ;
256263 let foundExecutable = false ;
257264 for ( ; ; ) {
@@ -260,14 +267,15 @@ export const makePreviewBrowser = Effect.fn("PreviewBrowser.make")(function* (
260267 const unixMode = entry . externalFileAttributes >>> 16 ;
261268 const unixType = unixMode & 0o170000 ;
262269 const isDirectory = entry . fileName . endsWith ( "/" ) ;
270+ const isSymlink = unixType === 0o120000 ;
263271 const relative = entry . fileName . startsWith ( root ) ? entry . fileName . slice ( root . length ) : null ;
264272 const target = relative === null ? null : path . resolve ( destination , relative ) ;
265273 if (
266274 relative === null ||
267275 target === null ||
268276 ( relative !== "" && ! target . startsWith ( `${ destination } ${ path . sep } ` ) ) ||
269277 relative . split ( "/" ) . includes ( ".." ) ||
270- ( unixType !== 0 && unixType !== ( isDirectory ? 0o040000 : 0o100000 ) ) ||
278+ ( unixType !== 0 && ! isSymlink && unixType !== ( isDirectory ? 0o040000 : 0o100000 ) ) ||
271279 ( entry . generalPurposeBitFlag & 1 ) !== 0 ||
272280 ! [ 0 , 8 ] . includes ( entry . compressionMethod )
273281 ) {
@@ -278,6 +286,21 @@ export const makePreviewBrowser = Effect.fn("PreviewBrowser.make")(function* (
278286 continue ;
279287 }
280288 yield * fs . makeDirectory ( path . dirname ( target ) , { recursive : true } ) ;
289+ if ( isSymlink ) {
290+ // macOS framework bundles link within themselves (Versions/Current); nothing may point out.
291+ const linked = yield * Effect . gen ( function * ( ) {
292+ const readable = yield * archive . streamEntry ( entry ) ;
293+ return yield * EffectNodeStream . fromReadable < Uint8Array , PreviewBrowserInstallError > ( {
294+ evaluate : ( ) => readable ,
295+ onError : wrapFailure ( "Could not unpack the browser." ) ,
296+ } ) . pipe ( Stream . decodeText ( ) , Stream . mkString ) ;
297+ } ) . pipe ( Effect . scoped ) ;
298+ if ( linked === "" || linked . startsWith ( "/" ) || linked . split ( "/" ) . includes ( ".." ) ) {
299+ return yield * unsafe ;
300+ }
301+ yield * fs . symlink ( linked , target ) ;
302+ continue ;
303+ }
281304 yield * Effect . gen ( function * ( ) {
282305 const readable = yield * archive . streamEntry ( entry ) ;
283306 yield * EffectNodeStream . fromReadable < Uint8Array , PreviewBrowserInstallError > ( {
@@ -289,11 +312,11 @@ export const makePreviewBrowser = Effect.fn("PreviewBrowser.make")(function* (
289312 if ( platform !== "win32" && ( unixMode & 0o777 ) !== 0 ) {
290313 yield * fs . chmod ( target , unixMode & 0o777 ) ;
291314 }
292- if ( relative === executableName ) foundExecutable = true ;
315+ if ( relative === binary ) foundExecutable = true ;
293316 }
294317 if ( ! foundExecutable ) {
295318 return yield * new PreviewBrowserInstallError ( {
296- detail : "The archive does not contain chrome-headless-shell ." ,
319+ detail : "The archive does not contain Chrome ." ,
297320 } ) ;
298321 }
299322 } ,
@@ -345,7 +368,15 @@ export const makePreviewBrowser = Effect.fn("PreviewBrowser.make")(function* (
345368 ) ,
346369 { discard : true } ,
347370 ) ;
348- return path . join ( installRoot , release . version , executableName ) ;
371+ // Earlier versions installed chrome-headless-shell, which this browser replaces.
372+ yield * fs
373+ . remove ( path . join ( toolsDir , "chrome-headless-shell" ) , { recursive : true , force : true } )
374+ . pipe (
375+ Effect . catch ( ( cause ) =>
376+ Effect . logWarning ( "Could not remove the old headless shell." , { cause } ) ,
377+ ) ,
378+ ) ;
379+ return path . join ( installRoot , release . version , binary ) ;
349380 } ,
350381 Effect . mapError ( wrapFailure ( "Could not save the browser in T3's home directory." ) ) ,
351382 ) ;
0 commit comments