14
14
* limitations under the License.
15
15
*/
16
16
17
- import * as path from 'path' ;
18
17
import * as os from 'os' ;
19
18
import { CRBrowser , CRBrowserContext } from '../chromium/crBrowser' ;
20
19
import { CRConnection , CRSession } from '../chromium/crConnection' ;
@@ -77,17 +76,18 @@ export class ElectronApplication extends EventEmitter {
77
76
private async _onPage ( page : ElectronPage ) {
78
77
// Needs to be sync.
79
78
const windowId = ++ this . _lastWindowId ;
80
- // Can be async.
81
- const handle = await this . _nodeElectronHandle ! . evaluateHandle ( ( { BrowserWindow } , windowId ) => BrowserWindow . fromId ( windowId ) , windowId ) . catch ( e => { } ) ;
82
- if ( ! handle )
83
- return ;
84
- page . browserWindow = handle ;
85
- page . _browserWindowId = windowId ;
86
79
page . on ( Page . Events . Close , ( ) => {
87
80
page . browserWindow . dispose ( ) ;
88
81
this . _windows . delete ( page ) ;
89
82
} ) ;
83
+ page . _browserWindowId = windowId ;
90
84
this . _windows . add ( page ) ;
85
+
86
+ // Below is async.
87
+ const handle = await this . _nodeElectronHandle ! . evaluateHandle ( ( { BrowserWindow } , windowId ) => BrowserWindow . fromId ( windowId ) , windowId ) . catch ( e => { } ) ;
88
+ if ( ! handle )
89
+ return ;
90
+ page . browserWindow = handle ;
91
91
await runAbortableTask ( progress => page . mainFrame ( ) . _waitForLoadState ( progress , 'domcontentloaded' ) , page . _timeoutSettings . navigationTimeout ( { } ) ) . catch ( e => { } ) ; // can happen after detach
92
92
this . emit ( ElectronApplication . Events . Window , page ) ;
93
93
}
@@ -126,16 +126,12 @@ export class ElectronApplication extends EventEmitter {
126
126
}
127
127
128
128
async _init ( ) {
129
- this . _nodeSession . once ( 'Runtime.executionContextCreated' , event => {
130
- this . _nodeExecutionContext = new js . ExecutionContext ( new CRExecutionContext ( this . _nodeSession , event . context ) ) ;
129
+ this . _nodeSession . on ( 'Runtime.executionContextCreated' , ( event : any ) => {
130
+ if ( event . context . auxData && event . context . auxData . isDefault )
131
+ this . _nodeExecutionContext = new js . ExecutionContext ( new CRExecutionContext ( this . _nodeSession , event . context ) ) ;
131
132
} ) ;
132
133
await this . _nodeSession . send ( 'Runtime.enable' , { } ) . catch ( e => { } ) ;
133
- this . _nodeElectronHandle = await js . evaluate ( this . _nodeExecutionContext ! , false /* returnByValue */ , ( ) => {
134
- // Resolving the race between the debugger and the boot-time script.
135
- if ( ( global as any ) . _playwrightRun )
136
- return ( global as any ) . _playwrightRun ( ) ;
137
- return new Promise ( f => ( global as any ) . _playwrightRunCallback = f ) ;
138
- } ) ;
134
+ this . _nodeElectronHandle = await js . evaluate ( this . _nodeExecutionContext ! , false /* returnByValue */ , `process.mainModule.require('electron')` ) ;
139
135
}
140
136
}
141
137
@@ -151,7 +147,7 @@ export class Electron {
151
147
controller . setLogName ( 'browser' ) ;
152
148
return controller . run ( async progress => {
153
149
let app : ElectronApplication | undefined = undefined ;
154
- const electronArguments = [ '--inspect=0' , '--remote-debugging-port=0' , '--require' , path . join ( __dirname , 'electronLoader.js' ) , ...args ] ;
150
+ const electronArguments = [ '--inspect=0' , '--remote-debugging-port=0' , ...args ] ;
155
151
156
152
if ( os . platform ( ) === 'linux' ) {
157
153
const runningAsRoot = process . geteuid && process . geteuid ( ) === 0 ;
@@ -171,7 +167,7 @@ export class Electron {
171
167
cwd : options . cwd ,
172
168
tempDirectories : [ ] ,
173
169
attemptToGracefullyClose : ( ) => app ! . close ( ) ,
174
- onExit : ( exitCode , signal ) => { } ,
170
+ onExit : ( ) => { } ,
175
171
} ) ;
176
172
177
173
const nodeMatch = await waitForLine ( progress , launchedProcess , launchedProcess . stderr , / ^ D e b u g g e r l i s t e n i n g o n ( w s : \/ \/ .* ) $ / ) ;
0 commit comments