How to block mailto opening email client from inside iframe in Electron webapp?

78 Views Asked by At

I have a fullscreen, kiosk Electron webapp with an iframe of an online website in it. I can use the sandbox attribute of the iframe to block new windows and popups opening from links, but the mailto: links open the system default mail client and make the user leave the Electron app. Is there any way to block/intercept these links? I have no access to the contents of the frames. I've already tried the will-navigate event for the window, but that doesn't fire on clicking inside the frame.

1

There are 1 best solutions below

0
samuset On BEST ANSWER

Turns out there is an event that does the same thing as will-navigate but handling links inside sub-frames of the pages, such as iframes: will-frame-navigate. This fixed my issue:

win.webContents.on( 'will-frame-navigate', ( event, url ) => {
    if ( url.startsWith( 'mailto:' ) )
    {
        event.preventDefault();
    }
});