当我设置nativeWindowOpen并且nodeIntegration为true时,应用程序崩溃

时间:2020-11-11 03:47:45

标签: electron

当前,我正在尝试使用window.open从渲染器进程中打开外部URL。为此,我创建了nodeIntegration时设置了nativeWindowOpen并且trueBrowserWindow。如果我使用的电子版本至少为8.x,则可以使用,但电子版7.x会崩溃。

我在下面有一个代码示例:

package.json

{
  "name": "window-open-app",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "electron ."
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "electron": "7.3.2" // If I update to version 8.0.0, It will work. 
  }
}

index.js

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

function startTest() {
  let parent_window = new BrowserWindow({
    show: true,
    title: "parent",
    webPreferences: {
      nativeWindowOpen: true,
      nodeIntegration: true,
      // nodeIntegrationInSubFrames: true,
    },
  });
  parent_window.loadFile("parent.html");
  parent_window.webContents.on("new-window", (event, url, frameName) => {
    event.preventDefault(); 
    shell.openExternal(url);
  });
}

app.on("ready", startTest);

parent.html

<body>
  Main window
</body>
<script>
   window.open('https://google.com');   
</script>

0 个答案:

没有答案