MCPcopy Create free account
hub / github.com/deta/surf / setupWebContentsViewWebContentsHandlers

Function setupWebContentsViewWebContentsHandlers

app/src/main/mainWindow.ts:524–600  ·  view source on GitHub ↗
(contents: Electron.WebContents)

Source from the content-addressed store, hash-verified

522}
523
524function setupWebContentsViewWebContentsHandlers(contents: Electron.WebContents) {
525 contents.setWindowOpenHandler((details: Electron.HandlerDetails) => {
526 try {
527 log.log('WebContentsView Window open handler called with details:', details)
528 // If there is a frame name or features provided we assume the request
529 // is part of a auth flow and we create a new isolated window for it
530 const shouldCreateWindow =
531 details.disposition === 'new-window' &&
532 (details.frameName !== '' || details.features !== '')
533
534 if (shouldCreateWindow) {
535 // IMPORTANT NOTE: DO NOT expose any sort of Node.js capabilities to the newly
536 // created window here. The creation of it is controlled from the renderer. Because
537 // of this, Surf won't play well with websites that for some reason utilizes more
538 // than one window. In the future, Each new window we create should receive its own
539 // instance of Surf.
540 return {
541 action: 'allow',
542 createWindow: undefined,
543 outlivesOpener: false,
544 overrideBrowserWindowOptions: {
545 webPreferences: {
546 contextIsolation: true,
547 nodeIntegration: false,
548 sandbox: true,
549 webSecurity: true
550 }
551 }
552 }
553 }
554
555 const url = new URL(details.url)
556 if (
557 url.protocol === 'surf:' ||
558 url.protocol === 'surflet:' ||
559 url.protocol === 'surf-internal:'
560 ) {
561 log.warn('[main] Denied new window request:', details)
562 return { action: 'deny' }
563 }
564
565 const mainWindow = getMainWindow()
566 if (mainWindow) {
567 log.log(
568 '[main] Sending new window request to main window:',
569 contents.id,
570 details.url,
571 details.disposition
572 )
573 IPC_EVENTS_MAIN.newWindowRequest.sendToWebContents(mainWindow.webContents, {
574 url: details.url,
575 disposition: details.disposition,
576 webContentsId: contents.id
577 })
578 } else {
579 log.warn('[main] No main window, cannot send new window request:', details)
580 }
581

Callers 1

createWindowFunction · 0.85

Calls 7

attachContextMenuFunction · 0.90
isMacFunction · 0.90
getMainWindowFunction · 0.85
logMethod · 0.80
warnMethod · 0.80
onMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected