1
1
/*eslint-env node */
2
2
3
- import { app , session , BrowserWindow , ipcMain , dialog } from "electron" ;
3
+ import { app , session , BrowserWindow , ipcMain , dialog , type HandlerDetails , WebContents , WindowOpenHandlerResponse } from "electron" ;
4
4
import { ElectronRecorder } from "./electron-recorder" ;
5
5
6
6
import {
@@ -176,14 +176,11 @@ class ElectronRecorderApp extends ElectronReplayApp {
176
176
}
177
177
178
178
createRecordWindow ( {
179
- // @ts -expect-error - TS2525 - Initializer provides no value for this binding element and the binding element has no default value.
180
- url,
179
+ url = "" ,
181
180
collId = "" ,
182
181
startRec = true ,
183
182
autorun = false ,
184
183
} = { } ) {
185
- console . log ( "start rec window: " + url ) ;
186
-
187
184
const recWindow = new BrowserWindow ( {
188
185
width : this . screenSize . width ,
189
186
height : this . screenSize . height ,
@@ -218,7 +215,7 @@ class ElectronRecorderApp extends ElectronReplayApp {
218
215
startRec ,
219
216
// @ts -expect-error - TS7006 - Parameter 'autorun' implicitly has an 'any' type.
220
217
autorun ,
221
- popupView = null ,
218
+ // popupView = null,
222
219
) {
223
220
const id = recWebContents . id ;
224
221
@@ -229,7 +226,7 @@ class ElectronRecorderApp extends ElectronReplayApp {
229
226
recWindow,
230
227
collId,
231
228
autorun,
232
- popup : popupView ,
229
+ popup : null ,
233
230
staticPrefix : this . staticContentPath ,
234
231
// @ts -expect-error - TS2339 - Property 'userAgent' does not exist on type 'ElectronRecorderApp'.
235
232
userAgent : this . userAgent ,
@@ -245,20 +242,17 @@ class ElectronRecorderApp extends ElectronReplayApp {
245
242
} ) ;
246
243
} ) ;
247
244
248
- const newWinContents = popupView
249
- ? // @ts -expect-error - TS2339 - Property 'webContents' does not exist on type 'never'.
250
- popupView . webContents
251
- : recWindow . webContents ;
245
+ const newWinContents = recWindow . webContents ;
252
246
253
- // @ts -expect-error - TS7006 - Parameter 'event' implicitly has an 'any' type. | TS7006 - Parameter 'url' implicitly has an 'any' type.
254
- newWinContents . on ( "new-window" , ( event , url ) => {
255
- event . preventDefault ( ) ;
247
+ newWinContents . setWindowOpenHandler ( ( details : HandlerDetails ) => {
248
+ const { url } = details ;
256
249
if ( url . startsWith ( STATIC_PREFIX ) ) {
257
- // @ts -expect-error - TS2531 - Object is possibly 'null'.
258
- this . mainWindow . loadURL ( url ) ;
259
- // @ts -expect-error - TS2531 - Object is possibly 'null'.
260
- this . mainWindow . show ( ) ;
250
+ this . mainWindow ! . loadURL ( url ) ;
251
+ this . mainWindow ! . show ( ) ;
252
+ return { action : 'deny' } ;
261
253
}
254
+
255
+ return { action : 'allow' } ;
262
256
} ) ;
263
257
264
258
ipcMain . on ( "popup-msg-" + id , async ( event , msg ) => {
@@ -278,37 +272,17 @@ class ElectronRecorderApp extends ElectronReplayApp {
278
272
}
279
273
} ) ;
280
274
281
- recWebContents . on (
282
- "new-window" ,
283
- (
284
- // @ts -expect-error - TS7006 - Parameter 'event' implicitly has an 'any' type.
285
- event ,
286
- // @ts -expect-error - TS7006 - Parameter 'url' implicitly has an 'any' type.
287
- url ,
288
- // @ts -expect-error - TS7006 - Parameter 'frameName' implicitly has an 'any' type.
289
- frameName ,
290
- // @ts -expect-error - TS7006 - Parameter 'disposition' implicitly has an 'any' type.
291
- disposition ,
292
- // @ts -expect-error - TS7006 - Parameter 'options' implicitly has an 'any' type.
293
- options ,
294
- // @ts -expect-error - TS7006 - Parameter 'additionalFeatures' implicitly has an 'any' type.
295
- additionalFeatures ,
296
- // @ts -expect-error - TS7006 - Parameter 'referrer' implicitly has an 'any' type.
297
- referrer ,
298
- ) => {
299
- event . preventDefault ( ) ;
300
- event . newGuest = this . createRecordWindow ( { url, collId, startRec } ) ;
301
- console . log (
302
- "new-window" ,
303
- url ,
304
- frameName ,
305
- disposition ,
306
- options ,
307
- additionalFeatures ,
308
- referrer ,
309
- ) ;
310
- } ,
311
- ) ;
275
+ recWebContents . setWindowOpenHandler ( ( details : HandlerDetails ) : WindowOpenHandlerResponse => {
276
+ const { url } = details ;
277
+ return {
278
+ action : "allow" ,
279
+ outlivesOpener : true ,
280
+ createWindow : ( ) => {
281
+ const win = this . createRecordWindow ( { url, collId, startRec } ) ;
282
+ return win . webContents ;
283
+ }
284
+ }
285
+ } ) ;
312
286
313
287
recWebContents . on ( "destroyed" , ( ) => {
314
288
// @ts -expect-error - TS2339 - Property 'recorders' does not exist on type 'ElectronRecorderApp'.
0 commit comments