Skip to content

Commit 7b7e855

Browse files
committed
Dynamically resolve latest Chromium build ID in browser handler
1 parent 9ee298d commit 7b7e855

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

‎apps/editor/src/views/prompt/backend/message-handlers/handle-run-browser.ts‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import * as os from 'os'
44
import * as fs from 'fs'
55
import * as crypto from 'crypto'
66
import { spawn } from 'child_process'
7-
import { Browser, detectBrowserPlatform, install } from '@puppeteer/browsers'
7+
import {
8+
Browser,
9+
detectBrowserPlatform,
10+
install,
11+
resolveBuildId
12+
} from '@puppeteer/browsers'
813
import { t } from '@/i18n'
914
import { PromptViewProvider } from '../prompt-view-provider'
1015
import { LAST_SELECTED_BROWSER_PROFILE_STATE_KEY } from '@/constants/state-keys'
1116

12-
const CHROMIUM_BUILD_ID = '1717349'
13-
1417
const launch_browser = (params: {
1518
executable_path: string
1619
user_data_dir: string
@@ -33,7 +36,6 @@ const launch_browser = (params: {
3336
const args = [
3437
`--user-data-dir=${params.user_data_dir}`,
3538
`--load-extension=${params.extension_path}`,
36-
'--disable-infobars',
3739
'--no-first-run'
3840
]
3941

@@ -179,11 +181,7 @@ export const handle_run_browser = async (
179181
if (fs.existsSync(cached_path_file)) {
180182
try {
181183
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-
) {
184+
if (typeof cached.path === 'string' && fs.existsSync(cached.path)) {
187185
launch_browser({
188186
executable_path: cached.path,
189187
user_data_dir,
@@ -230,10 +228,20 @@ export const handle_run_browser = async (
230228
return
231229
}
232230

231+
const build_id = await resolveBuildId(
232+
Browser.CHROMIUM,
233+
platform,
234+
'latest'
235+
)
236+
237+
if (token.isCancellationRequested) {
238+
return
239+
}
240+
233241
let last_percentage = 0
234242
const installed_browser = await install({
235243
browser: Browser.CHROMIUM,
236-
buildId: CHROMIUM_BUILD_ID,
244+
buildId: build_id,
237245
cacheDir: browser_dir,
238246
platform,
239247
downloadProgressCallback: (downloaded_bytes, total_bytes) => {
@@ -265,7 +273,7 @@ export const handle_run_browser = async (
265273
fs.writeFileSync(
266274
cached_path_file,
267275
JSON.stringify({
268-
version: CHROMIUM_BUILD_ID,
276+
version: build_id,
269277
path: executable_path
270278
})
271279
)

0 commit comments

Comments
 (0)