@@ -10,15 +10,23 @@ import { mkdtemp } from 'fs/promises'
1010import path from 'path'
1111import os from 'os'
1212import { appSettings } from './main'
13+ import { exec , spawn } from 'child_process'
14+ import { getPlatform } from './utils/electron'
15+ import log from 'electron-log/main'
1316
1417const createUserDataDir = async ( ) => {
1518 return mkdtemp ( path . join ( os . tmpdir ( ) , 'k6-studio-' ) )
1619}
1720
18- export function getBrowserPath ( ) {
21+ export async function getBrowserPath ( ) {
1922 const { recorder } = appSettings
2023
2124 if ( recorder . detectBrowserPath ) {
25+ if ( getPlatform ( ) === 'linux' && process . arch === 'arm64' ) {
26+ // Chrome is not available for arm64, use Chromium instead
27+ return await getChromiumPath ( )
28+ }
29+
2230 return computeSystemExecutablePath ( {
2331 browser : Browser . CHROME ,
2432 channel : ChromeReleaseChannel . STABLE ,
@@ -32,7 +40,7 @@ export const launchBrowser = async (
3240 browserWindow : BrowserWindow ,
3341 url ?: string
3442) => {
35- const path = getBrowserPath ( )
43+ const path = await getBrowserPath ( )
3644 console . info ( `browser path: ${ path } ` )
3745
3846 const userDataDir = await createUserDataDir ( )
@@ -54,24 +62,51 @@ export const launchBrowser = async (
5462 return Promise . resolve ( )
5563 }
5664
65+ const args = [
66+ '--new' ,
67+ '--args' ,
68+ `--user-data-dir=${ userDataDir } ` ,
69+ '--hide-crash-restore-bubble' ,
70+ '--test-type' ,
71+ '--no-default-browser-check' ,
72+ '--no-first-run' ,
73+ '--disable-background-networking' ,
74+ '--disable-component-update' ,
75+ '--disable-search-engine-choice-screen' ,
76+ `--proxy-server=http://localhost:${ appSettings . proxy . port } ` ,
77+ `--ignore-certificate-errors-spki-list=${ certificateSPKI } ` ,
78+ disableChromeOptimizations ,
79+ url ?. trim ( ) || 'about:blank' ,
80+ ]
81+
82+ // if we are on linux we spawn the browser directly and attach the on exit callback
83+ if ( getPlatform ( ) === 'linux' ) {
84+ const browserProc = spawn ( path , args )
85+ browserProc . once ( 'exit' , sendBrowserClosedEvent )
86+ return browserProc
87+ }
88+
89+ // macOS & windows
5790 return launch ( {
5891 executablePath : path ,
59- args : [
60- '--new' ,
61- '--args' ,
62- `--user-data-dir=${ userDataDir } ` ,
63- '--hide-crash-restore-bubble' ,
64- '--test-type' ,
65- '--no-default-browser-check' ,
66- '--no-first-run' ,
67- '--disable-background-networking' ,
68- '--disable-component-update' ,
69- '--disable-search-engine-choice-screen' ,
70- `--proxy-server=http://localhost:${ appSettings . proxy . port } ` ,
71- `--ignore-certificate-errors-spki-list=${ certificateSPKI } ` ,
72- disableChromeOptimizations ,
73- url ?. trim ( ) || 'about:blank' ,
74- ] ,
92+ args : args ,
7593 onExit : sendBrowserClosedEvent ,
7694 } )
7795}
96+
97+ function getChromiumPath ( ) : Promise < string > {
98+ return new Promise ( ( resolve , reject ) => {
99+ exec ( 'which chromium' , ( error , stdout , stderr ) => {
100+ if ( error ) {
101+ log . error ( error )
102+ return reject ( error )
103+ }
104+ if ( stderr ) {
105+ log . error ( stderr )
106+ return reject ( stderr )
107+ }
108+
109+ return resolve ( stdout . trim ( ) )
110+ } )
111+ } )
112+ }
0 commit comments