Skip to content

Commit 7dcf2e4

Browse files
committed
Switch browser implementation from Chrome to Chromium
- should install raw chromium@1717349 instead of 'chrome for testing'. store version in generically named file .chromium-path
1 parent d27add4 commit 7dcf2e4

1 file changed

Lines changed: 31 additions & 23 deletions

File tree

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

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ 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 {
8-
Browser,
9-
detectBrowserPlatform,
10-
install,
11-
resolveBuildId
12-
} from '@puppeteer/browsers'
7+
import { Browser, detectBrowserPlatform, install } from '@puppeteer/browsers'
138
import { t } from '@/i18n'
149
import { PromptViewProvider } from '../prompt-view-provider'
1510
import { LAST_SELECTED_BROWSER_PROFILE_STATE_KEY } from '@/constants/state-keys'
1611

12+
const CHROMIUM_BUILD_ID = '1717349'
13+
1714
const 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

Comments
 (0)