Skip to content

Instantly share code, notes, and snippets.

@yuya-oc
Created April 21, 2016 12:07
Show Gist options
  • Save yuya-oc/4832c866973d93ba65227a94758c431a to your computer and use it in GitHub Desktop.
Save yuya-oc/4832c866973d93ba65227a94758c431a to your computer and use it in GitHub Desktop.
Test for webview.getWebContents() login event
<html>
<body>
<input type="button" value="Load" onclick="onButtonClick()"></input>
<webview id="webview0" src="https://example.com" style="display:inline-flex; width:640px; height:480px"></webview>
</body>
<script>
var handler = function(event, request, authInfo, callback){
event.preventDefault();
console.log(event);
console.log(request);
console.log(authInfo);
console.log(callback);
callback('USER', 'PASSWORD');
};
function onButtonClick(){
var webview = document.getElementById("webview0");
webview.getWebContents().once('login', handler);
webview.src = 'http://NEED_AUTH.SAMPLE';
}
</script>
</html>
'use strict';
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
var mainWindow;
app.on('ready',()=>{
mainWindow = new BrowserWindow();
mainWindow.loadURL('file://'+__dirname+'/index.html');
});
/*
app.on('login',(event, webContents, request, authInfo, callback)=>{
console.log(callback);
});
*/
{
"name": "webview login test",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment