Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add electron API to open external URLs. #153

Closed
wants to merge 1 commit into from
Closed

Add electron API to open external URLs. #153

wants to merge 1 commit into from

Conversation

robinjhuang
Copy link
Member

Resolves #138

ComfyUI_frontend needs to add something like :

document.addEventListener('click', (event) => {
    const target = event.target as HTMLElement;
    const anchor = target.closest('a');
    
    if (anchor && anchor.href && anchor.href.startsWith('http')) {
      event.preventDefault();
      electronAPI.openExternal(anchor.href);
    }
  });

Copy link
Member

@huchenlei huchenlei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a solution without modification on the frontend side? Some extensions might have links that out of our control.

Claude gives following solution:

const { app, BrowserWindow, shell } = require('electron')

function createWindow() {
  const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      webviewTag: true,
      nodeIntegration: true,
      contextIsolation: false
    }
  })

  // Load your HTML file containing the webview
  win.loadFile('index.html')
}

app.whenReady().then(createWindow)

// In your renderer process (index.html)
<html>
<body>
  <webview id="myWebview" src="https://example.com"></webview>
  <script>
    const webview = document.getElementById('myWebview')
    
    webview.addEventListener('new-window', (event) => {
      event.preventDefault()
      shell.openExternal(event.url)
    })
    
    webview.addEventListener('will-navigate', (event) => {
      // Optional: intercept navigation events as well
      event.preventDefault()
      shell.openExternal(event.url)
    })
  </script>
</body>
</html>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Open links in system browser
2 participants