@@ -4,16 +4,13 @@ import * as os from 'os'
44import * as fs from 'fs'
55import * as crypto from 'crypto'
66import { spawn } from 'child_process'
7- import {
8- Browser ,
9- detectBrowserPlatform ,
10- install ,
11- resolveBuildId
12- } from '@puppeteer/browsers'
7+ import { Browser , detectBrowserPlatform , install } from '@puppeteer/browsers'
138import { t } from '@/i18n'
149import { PromptViewProvider } from '../prompt-view-provider'
1510import { LAST_SELECTED_BROWSER_PROFILE_STATE_KEY } from '@/constants/state-keys'
1611
12+ const CHROMIUM_BUILD_ID = '1717349'
13+
1714const launch_browser = ( params : {
1815 executable_path : string
1916 user_data_dir : string
@@ -177,19 +174,25 @@ export const handle_run_browser = async (
177174 'out'
178175 )
179176 const user_data_dir = path . join ( browser_dir , 'profiles' , selected_profile )
180- const cached_path_file = path . join ( browser_dir , '.chrome-157 -path' )
177+ const cached_path_file = path . join ( browser_dir , '.chromium -path' )
181178
182179 if ( fs . existsSync ( cached_path_file ) ) {
183- const executable_path = fs . readFileSync ( cached_path_file , 'utf-8' ) . trim ( )
184- if ( fs . existsSync ( executable_path ) ) {
185- launch_browser ( {
186- executable_path,
187- user_data_dir,
188- extension_path,
189- cwc_dir
190- } )
191- return
192- }
180+ try {
181+ const cached = JSON . parse ( fs . readFileSync ( cached_path_file , 'utf-8' ) )
182+ if (
183+ cached . version === CHROMIUM_BUILD_ID &&
184+ typeof cached . path === 'string' &&
185+ fs . existsSync ( cached . path )
186+ ) {
187+ launch_browser ( {
188+ executable_path : cached . path ,
189+ user_data_dir,
190+ extension_path,
191+ cwc_dir
192+ } )
193+ return
194+ }
195+ } catch { }
193196 }
194197
195198 const download_action = t (
@@ -220,20 +223,19 @@ export const handle_run_browser = async (
220223 try {
221224 const platform = detectBrowserPlatform ( )
222225 if ( ! platform ) {
223- throw new Error ( 'Unsupported platform for Chrome for Testing .' )
226+ throw new Error ( 'Unsupported platform for Chromium .' )
224227 }
225228
226- const build_id = await resolveBuildId ( Browser . CHROME , platform , '157' )
227-
228229 if ( token . isCancellationRequested ) {
229230 return
230231 }
231232
232233 let last_percentage = 0
233234 const installed_browser = await install ( {
234- browser : Browser . CHROME ,
235- buildId : build_id ,
235+ browser : Browser . CHROMIUM ,
236+ buildId : CHROMIUM_BUILD_ID ,
236237 cacheDir : browser_dir ,
238+ platform,
237239 downloadProgressCallback : ( downloaded_bytes , total_bytes ) => {
238240 if ( token . isCancellationRequested ) {
239241 throw new Error ( 'Download cancelled' )
@@ -260,7 +262,13 @@ export const handle_run_browser = async (
260262 throw new Error ( 'Could not determine Browser path.' )
261263 }
262264
263- fs . writeFileSync ( cached_path_file , executable_path )
265+ fs . writeFileSync (
266+ cached_path_file ,
267+ JSON . stringify ( {
268+ version : CHROMIUM_BUILD_ID ,
269+ path : executable_path
270+ } )
271+ )
264272 launch_browser ( {
265273 executable_path,
266274 user_data_dir,
0 commit comments