Merge pull request #5967 from electron/window-opener-webview
Support window.opener from windows opened from a <webview>
This commit is contained in:
commit
21081549fd
3 changed files with 88 additions and 38 deletions
|
@ -1,12 +1,11 @@
|
|||
|
||||
const assert = require('assert')
|
||||
const http = require('http')
|
||||
const path = require('path')
|
||||
const ws = require('ws')
|
||||
const url = require('url')
|
||||
const remote = require('electron').remote
|
||||
|
||||
const BrowserWindow = remote.require('electron').BrowserWindow
|
||||
const session = remote.require('electron').session
|
||||
const {BrowserWindow, session, webContents} = remote
|
||||
|
||||
const isCI = remote.getGlobal('isCi')
|
||||
|
||||
|
@ -235,7 +234,7 @@ describe('chromium feature', function () {
|
|||
else
|
||||
targetURL = 'file://' + fixtures + '/pages/base-page.html'
|
||||
b = window.open(targetURL)
|
||||
BrowserWindow.fromId(b.guestId).webContents.once('did-finish-load', function () {
|
||||
webContents.fromId(b.guestId).once('did-finish-load', function () {
|
||||
assert.equal(b.location, targetURL)
|
||||
b.close()
|
||||
done()
|
||||
|
@ -246,10 +245,10 @@ describe('chromium feature', function () {
|
|||
// Load a page that definitely won't redirect
|
||||
var b
|
||||
b = window.open('about:blank')
|
||||
BrowserWindow.fromId(b.guestId).webContents.once('did-finish-load', function () {
|
||||
webContents.fromId(b.guestId).once('did-finish-load', function () {
|
||||
// When it loads, redirect
|
||||
b.location = 'file://' + fixtures + '/pages/base-page.html'
|
||||
BrowserWindow.fromId(b.guestId).webContents.once('did-finish-load', function () {
|
||||
webContents.fromId(b.guestId).once('did-finish-load', function () {
|
||||
// After our second redirect, cleanup and callback
|
||||
b.close()
|
||||
done()
|
||||
|
@ -308,7 +307,7 @@ describe('chromium feature', function () {
|
|||
}
|
||||
window.addEventListener('message', listener)
|
||||
b = window.open('file://' + fixtures + '/pages/window-open-postMessage.html', '', 'show=no')
|
||||
BrowserWindow.fromId(b.guestId).webContents.once('did-finish-load', function () {
|
||||
webContents.fromId(b.guestId).once('did-finish-load', function () {
|
||||
b.postMessage('testing', '*')
|
||||
})
|
||||
})
|
||||
|
@ -327,6 +326,25 @@ describe('chromium feature', function () {
|
|||
window.addEventListener('message', listener)
|
||||
b = window.open('file://' + fixtures + '/pages/window-opener-postMessage.html', '', 'show=no')
|
||||
})
|
||||
|
||||
it('supports windows opened from a <webview>', function (done) {
|
||||
const webview = new WebView()
|
||||
webview.addEventListener('console-message', function (e) {
|
||||
webview.remove()
|
||||
assert.equal(e.message, 'message')
|
||||
done()
|
||||
})
|
||||
webview.allowpopups = true
|
||||
webview.src = url.format({
|
||||
pathname: `${fixtures}/pages/webview-opener-postMessage.html`,
|
||||
protocol: 'file',
|
||||
query: {
|
||||
p: `${fixtures}/pages/window-opener-postMessage.html`
|
||||
},
|
||||
slashes: true
|
||||
})
|
||||
document.body.appendChild(webview)
|
||||
})
|
||||
})
|
||||
|
||||
describe('creating a Uint8Array under browser side', function () {
|
||||
|
|
19
spec/fixtures/pages/webview-opener-postMessage.html
vendored
Normal file
19
spec/fixtures/pages/webview-opener-postMessage.html
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<script>
|
||||
var windowUrl = decodeURIComponent(window.location.search.substring(3))
|
||||
var opened = window.open(windowUrl, '', 'show=no')
|
||||
window.addEventListener('message', function (event) {
|
||||
try {
|
||||
opened.close()
|
||||
} finally {
|
||||
console.log(event.data)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue