在隔离的框架和进程中显示外部 Web 内容。
Process: Renderer 这个类不是从“electron”导出的
模块。它只能作为其他方法的返回值使用
电子 API。
使用 webview 标签嵌入“访客”内容(例如网页)
你的电子应用程序。来宾内容包含在 webview 中
容器。您的应用程序中的嵌入式页面控制访客如何
内容被布局和呈现。
与 iframe 不同,webview 运行在一个单独的进程中,而不是您的
应用程序。它没有与您的网页相同的权限和所有
您的应用程序和嵌入内容之间的交互将是
异步。这可以使您的应用免受嵌入内容的影响。
注意:从主机页面调用 web 视图的大多数方法都需要
同步调用主进程。
Reference
如果您使用 iframe 进行 google 签名,您将收到内容安全策略 (CSP) 错误
这样的结果
<iframe style="display: flex ;height: 1000px" width="100%" height="100%"
src="https://accounts.google.com/signin/v2/identifier?service=mail&passive=1209600&osid=1&continue=https%3A%2F%2Fmail.google.com%2Fmail%2Fu%2F0%2F&followup=https%3A%2F%2Fmail.google.com%2Fmail%2Fu%2F0%2F&emr=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin"></iframe>
解决方案:
Electron 已经引入了 webview 标签
所以结果可能是这样的
<webview style="
height: 500px;display: flex" src="https://accounts.google.com/signin/v2/identifier?service=mail&passive=1209600&osid=1&continue=https%3A%2F%2Fmail.google.com%2Fmail%2Fu%2F0%2F&followup=https%3A%2F%2Fmail.google.com%2Fmail%2Fu%2F0%2F&emr=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin" ></webview>
注意:
您必须在Browserwindow 中添加webPreferences 属性并且webview 标签必须为true,否则view 标签将被隐藏。默认的 webview 标签是 false .like this
所以你必须像这样添加
function createWindow() {
win = new BrowserWindow({width: 800, height: 600, webPreferences: {webviewTag: true}})
win.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}))
}