Skip to content

Instantly share code, notes, and snippets.

@RobPruzan
Last active September 10, 2025 11:17
Show Gist options
  • Select an option

  • Save RobPruzan/1c6bb4ad5bd24d34eb244e1e55af9100 to your computer and use it in GitHub Desktop.

Select an option

Save RobPruzan/1c6bb4ad5bd24d34eb244e1e55af9100 to your computer and use it in GitHub Desktop.

Revisions

  1. RobPruzan revised this gist Sep 10, 2025. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion index.ts
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    mainWindow.webContents.setWindowOpenHandler((details) => {
    export const portalViews = new Map<string, WebContentsView>()

    mainWindow.webContents.setWindowOpenHandler((details) => {
    const { frameName } = details
    if (frameName && frameName.startsWith('portal:')) {
    const portalId = frameName.slice('portal:'.length)
  2. RobPruzan created this gist Sep 10, 2025.
    46 changes: 46 additions & 0 deletions index.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    mainWindow.webContents.setWindowOpenHandler((details) => {
    const { frameName } = details
    if (frameName && frameName.startsWith('portal:')) {
    const portalId = frameName.slice('portal:'.length)
    if (portalViews.has(portalId)) {
    return { action: 'deny' }
    }
    return {
    action: 'allow',
    createWindow: (options) => {
    const wc = (options as any).webContents as Electron.WebContents
    const view = new WebContentsView({ webContents: wc })
    view.setBackgroundColor('#00000000')
    view.setBounds({ x: 0, y: 0, width: 1, height: 1 })
    mainWindow!.contentView.addChildView(view)
    portalViews.set(portalId, view)
    wc.once('destroyed', () => {
    try {
    mainWindow?.contentView.removeChildView(view)
    } catch {}
    portalViews.delete(portalId)
    })
    return wc
    }
    }
    }

    // todo: good impl
    if (details.url) shell.openExternal(details.url)
    return { action: 'deny' }
    })

    ipcMain.on(
    'portal:update-bounds',
    (
    _e,
    payload: { id: string; bounds: { x: number; y: number; width: number; height: number } }
    ) => {
    const view = portalViews.get(payload.id)
    if (!view) return
    view.setBounds(payload.bounds)
    try {
    mainWindow!.contentView.addChildView(view)
    } catch {}
    }
    )