@@ -21,6 +21,8 @@ import { kBrowserCloseMessageId } from './wkConnection';
21
21
import { wrapInASCIIBox } from '../utils/ascii' ;
22
22
import { BrowserType , kNoXServerRunningError } from '../browserType' ;
23
23
import { WKBrowser } from '../webkit/wkBrowser' ;
24
+ import { spawnAsync } from '../utils/spawnAsync' ;
25
+ import { registry } from '../registry' ;
24
26
25
27
import type { BrowserOptions } from '../browser' ;
26
28
import type { SdkObject } from '../instrumentation' ;
@@ -37,10 +39,11 @@ export class WebKit extends BrowserType {
37
39
return WKBrowser . connect ( this . attribution . playwright , transport , options ) ;
38
40
}
39
41
40
- override amendEnvironment ( env : NodeJS . ProcessEnv , userDataDir : string , isPersistent : boolean ) : NodeJS . ProcessEnv {
42
+ override amendEnvironment ( env : NodeJS . ProcessEnv , userDataDir : string , isPersistent : boolean , options : types . LaunchOptions ) : NodeJS . ProcessEnv {
41
43
return {
42
44
...env ,
43
45
CURL_COOKIE_JAR_PATH : process . platform === 'win32' && isPersistent ? path . join ( userDataDir , 'cookiejar.db' ) : undefined ,
46
+ WEBKIT_EXECUTABLE : options . channel === 'webkit-wsl' ? registry . findExecutable ( 'webkit-wsl' ) ! . wslExecutablePath ! : undefined
44
47
} ;
45
48
}
46
49
@@ -57,20 +60,29 @@ export class WebKit extends BrowserType {
57
60
transport . send ( { method : 'Playwright.close' , params : { } , id : kBrowserCloseMessageId } ) ;
58
61
}
59
62
60
- override defaultArgs ( options : types . LaunchOptions , isPersistent : boolean , userDataDir : string ) : string [ ] {
63
+ override async defaultArgs ( options : types . LaunchOptions , isPersistent : boolean , userDataDir : string ) : Promise < string [ ] > {
61
64
const { args = [ ] , headless } = options ;
62
65
const userDataDirArg = args . find ( arg => arg . startsWith ( '--user-data-dir' ) ) ;
63
66
if ( userDataDirArg )
64
67
throw this . _createUserDataDirArgMisuseError ( '--user-data-dir' ) ;
65
68
if ( args . find ( arg => ! arg . startsWith ( '-' ) ) )
66
69
throw new Error ( 'Arguments can not specify page to be opened' ) ;
67
70
const webkitArguments = [ '--inspector-pipe' ] ;
68
- if ( process . platform === 'win32' )
71
+
72
+ if ( options . channel === 'webkit-wsl' ) {
73
+ if ( options . executablePath )
74
+ throw new Error ( 'Cannot specify executablePath when using the "webkit-wsl" channel.' ) ;
75
+ webkitArguments . unshift (
76
+ path . join ( __dirname , 'wsl/webkit-wsl-transport-server.js' ) ,
77
+ ) ;
78
+ }
79
+
80
+ if ( process . platform === 'win32' && options . channel !== 'webkit-wsl' )
69
81
webkitArguments . push ( '--disable-accelerated-compositing' ) ;
70
82
if ( headless )
71
83
webkitArguments . push ( '--headless' ) ;
72
84
if ( isPersistent )
73
- webkitArguments . push ( `--user-data-dir=${ userDataDir } ` ) ;
85
+ webkitArguments . push ( `--user-data-dir=${ options . channel === 'webkit-wsl' ? await translatePathToWSL ( userDataDir ) : userDataDir } ` ) ;
74
86
else
75
87
webkitArguments . push ( `--no-startup-window` ) ;
76
88
const proxy = options . proxyOverride || options . proxy ;
@@ -79,7 +91,7 @@ export class WebKit extends BrowserType {
79
91
webkitArguments . push ( `--proxy=${ proxy . server } ` ) ;
80
92
if ( proxy . bypass )
81
93
webkitArguments . push ( `--proxy-bypass-list=${ proxy . bypass } ` ) ;
82
- } else if ( process . platform === 'linux' ) {
94
+ } else if ( process . platform === 'linux' || ( process . platform === 'win32' && options . channel === 'webkit-wsl' ) ) {
83
95
webkitArguments . push ( `--proxy=${ proxy . server } ` ) ;
84
96
if ( proxy . bypass )
85
97
webkitArguments . push ( ...proxy . bypass . split ( ',' ) . map ( t => `--ignore-host=${ t } ` ) ) ;
@@ -97,3 +109,8 @@ export class WebKit extends BrowserType {
97
109
return webkitArguments ;
98
110
}
99
111
}
112
+
113
+ export async function translatePathToWSL ( path : string ) : Promise < string > {
114
+ const { stdout } = await spawnAsync ( 'wsl.exe' , [ '-d' , 'playwright' , '--cd' , '/home/pwuser' , 'wslpath' , path . replace ( / \\ / g, '\\\\' ) ] ) ;
115
+ return stdout . toString ( ) . trim ( ) ;
116
+ }
0 commit comments