I'm developing an electron application. When I load the google login page using iframe, I get an error: '403. That’s an error. We're sorry, but you do not have access to this page. That’s all we know.'
How can I skip this error and get the google login page?
Q: Why not use an electron window to load the google login page?
A: It's true that using an electron window to load the google login page doesn't have any errors! But electron window will consume more memory!
Please help me!
Display external web content in an isolated frame and process.
Process: Renderer This class is not exported from the 'electron' module. It is only available as a return value of other methods in the Electron API.
Use the webview tag to embed 'guest' content (such as web pages) in your Electron app. The guest content is contained within the webview container. An embedded page within your app controls how the guest content is laid out and rendered.
Unlike an iframe, the webview runs in a separate process than your app. It doesn't have the same permissions as your web page and all interactions between your app and embedded content will be asynchronous. This keeps your app safe from embedded content. Note: Most methods called on the webview from the host page require a synchronous call to the main process.
if you are using iframe for google sign you will get a content security policy (CSP) error A result like this
<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>
Solution:
Electron already introduced a webview tag
So The result may like this
<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>
NB:
You must add the webPreferences property in Browserwindow and the webview tag must be true otherwise the view tag will be hidden. The default webview tag is false .like this
So you must add 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
}))
}