Created
April 21, 2016 12:07
-
-
Save yuya-oc/4832c866973d93ba65227a94758c431a to your computer and use it in GitHub Desktop.
Test for webview.getWebContents() login event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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); | |
}); | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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