'electron setWindowOpenHandler is not a function

I created an Electron-App for my web-app, which uses SAML. I want to allow the saml window to show up.

So I used the BrowserWindow.WebContents.setWindowOpenHandler function.

I first tried it, where the window object is being instanciated with a new BrowserWindow. That didn't work. I found on GitHub a new method, using the event "web-contents-created"

//Erlaube SAML Authentifizierung, andere Seiten werden blockiert
app.on("web-contents-created", (createEvent, contents) => {
  contents.setWindowOpenHandler(({url}) => {
    if(url.startsWith("https://login.microsoftonline.com/")) {
      return {action: 'allow'};
    }
    else return {action: 'deny'};
  });
});

That didn't word either, I always get the same error messages: The error message after I start the application

I'm using TypeScript and it's valid code. I'm using Electron 17.1.2

Anyone knows why and how?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source