electron/spec/fixtures/pages/window-opener-targetOrigin.html

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
1.2 KiB
HTML
Raw Normal View History

<html>
<body>
<script type="text/javascript" charset="utf-8">
const url = require('url')
function tryPostMessage(...args) {
try {
window.opener.postMessage(...args)
} catch (e) {
console.error(e)
}
}
if (url.parse(window.location.href, true).query.opened != null) {
2017-04-26 17:55:38 +00:00
// Ensure origins are properly checked by removing a single character from the end
tryPostMessage('do not deliver substring origin', window.location.origin.substring(0, window.location.origin.length - 1))
tryPostMessage('do not deliver file://', 'file://')
tryPostMessage('do not deliver http without port', 'http://127.0.0.1')
tryPostMessage('do not deliver atom', 'atom://')
tryPostMessage('do not deliver null', 'null')
tryPostMessage('do not deliver \\:/', '\\:/')
tryPostMessage('do not deliver empty', '')
2017-04-26 18:03:11 +00:00
window.opener.postMessage('deliver', window.location.origin)
} else {
const opened = window.open(`${window.location.href}?opened=true`, '', 'show=no,contextIsolation=no,nodeIntegration=yes')
window.addEventListener('message', function (event) {
window.opener.postMessage(event.data, '*')
opened.close()
})
}
</script>
</body>
</html>