Introduction
In Electron js if you tried to access a highly secured website such as Gmail using webview or iframe it gives an alert regarding the app is not secured. this happens because our browser behind the scenes do other stuff to make each request secured. but the same website we try to use with some HTML components such as iframe or webview then this request is considered as insecure to make a request secured try following solutions.
I also came across the same problem after a little searching it didn't found any solution working then finally I came across the following solutions.
Context
Before we start let me give you a little bit of context. I tried to create something similar to a browser in my electron app. I used webview for that to display pages and URL page got loaded properly but When I try to open a Gmail account from this webview it gave me the alert. Electron application using Google OAuth: “this browser or app may not be secure”.
Demo.html
<webview id="foo" src="https://mail.google.com/" style="display:inline-flex; width:640px; height:480px"></webview>
app may not be secure
Solution
Our browser is a secured medium to send and receive data this takes care of securely transmission of data it appends headers to our request which identify user separately. but when we use electron js webview it gives an alert message of browser or app not secured. this happens because when we send a request to the secured api server checks for userAgent for chrome browser userAgent is chrome.
The alert message given in the above image shows that we unable to make a secured connection with just webview we need to take some extra efforts to solve this error. In my case, I tried three different ways to solve errors.
Solution 1:
if you are trying to load URL using webview you can simply add one useragent HTML attribute in it read this for more attribute related information. When I set the user-agent attribute in webview it just works like a miracle. You can try this.
<webview src="https://mail.google.com/" useragent="Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko"></webview>
Solution 2:
in electron js, we have one more option to load URL directly In your main process, while loading the URL you can pass the name of the user-agent it will resolve your issue.for more information read this.
win = new BrowserWindow({width: 800, height: 600});
win.loadURL(authUrl, {userAgent: 'Chrome'})
0 Comments