@@ -286,6 +286,32 @@ function runApp() {
286
286
} )
287
287
}
288
288
289
+ // Electron defaults to approving all permission checks and permission requests.
290
+ // FreeTube only needs a few permissions, so we reject requests for other permissions
291
+ // and reject all requests on non-FreeTube URLs.
292
+ //
293
+ // FreeTube needs the following permissions:
294
+ // - "fullscreen": So that the video player can enter full screen
295
+ // - "clipboard-sanitized-write": To allow the user to copy video URLs and error messages
296
+
297
+ session . defaultSession . setPermissionCheckHandler ( ( webContents , permission , requestingOrigin ) => {
298
+ if ( ! isFreeTubeUrl ( requestingOrigin ) ) {
299
+ return false
300
+ }
301
+
302
+ return permission === 'fullscreen' || permission === 'clipboard-sanitized-write'
303
+ } )
304
+
305
+ session . defaultSession . setPermissionRequestHandler ( ( webContents , permission , callback ) => {
306
+ if ( ! isFreeTubeUrl ( webContents . getURL ( ) ) ) {
307
+ // eslint-disable-next-line n/no-callback-literal
308
+ callback ( false )
309
+ return
310
+ }
311
+
312
+ callback ( permission === 'fullscreen' || permission === 'clipboard-sanitized-write' )
313
+ } )
314
+
289
315
let docArray
290
316
try {
291
317
docArray = await baseHandlers . settings . _findAppReadyRelatedSettings ( )
@@ -547,6 +573,19 @@ function runApp() {
547
573
}
548
574
}
549
575
576
+ /**
577
+ * @param {string } urlString
578
+ */
579
+ function isFreeTubeUrl ( urlString ) {
580
+ const { protocol, host, pathname } = new URL ( urlString )
581
+
582
+ if ( process . env . NODE_ENV === 'development' ) {
583
+ return protocol === 'http:' && host === 'localhost:9080' && ( pathname === '/' || pathname === '/index.html' )
584
+ } else {
585
+ return protocol === 'app:' && host === 'bundle' && pathname === '/index.html'
586
+ }
587
+ }
588
+
550
589
async function installDevTools ( ) {
551
590
try {
552
591
/* eslint-disable */
0 commit comments