Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: call loadUrl when opening new windows from links (#34189)
* fix: call loadUrl when opening new windows from links * spec: add regression test Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
- Loading branch information
1 parent
21b8200
commit 4ecaae9
Showing
7 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
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
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
11 changes: 11 additions & 0 deletions
11
spec-main/fixtures/apps/open-new-window-from-link/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'"> | ||
<title>Hello World!</title> | ||
</head> | ||
<body> | ||
<a href="./new-window-page.html">Open New Window</a> | ||
</body> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const { app, BrowserWindow } = require('electron'); | ||
const path = require('path'); | ||
|
||
async function createWindow () { | ||
const mainWindow = new BrowserWindow({ | ||
width: 800, | ||
height: 600, | ||
x: 100, | ||
y: 100, | ||
webPreferences: { | ||
preload: path.join(__dirname, 'preload.js'), | ||
contextIsolation: false, | ||
nodeIntegration: true | ||
} | ||
}); | ||
|
||
await mainWindow.loadFile('index.html'); | ||
|
||
const rect = await mainWindow.webContents.executeJavaScript('JSON.parse(JSON.stringify(document.querySelector("a").getBoundingClientRect()))'); | ||
const x = rect.x + rect.width / 2; | ||
const y = rect.y + rect.height / 2; | ||
|
||
function click (x, y, options) { | ||
x = Math.floor(x); | ||
y = Math.floor(y); | ||
mainWindow.webContents.sendInputEvent({ | ||
type: 'mouseDown', | ||
button: 'left', | ||
x, | ||
y, | ||
clickCount: 1, | ||
...options | ||
}); | ||
|
||
mainWindow.webContents.sendInputEvent({ | ||
type: 'mouseUp', | ||
button: 'left', | ||
x, | ||
y, | ||
clickCount: 1, | ||
...options | ||
}); | ||
} | ||
|
||
click(x, y, { modifiers: ['shift'] }); | ||
} | ||
|
||
app.whenReady().then(() => { | ||
app.on('web-contents-created', (e, wc) => { | ||
wc.on('render-process-gone', (e, details) => { | ||
console.error(details); | ||
process.exit(1); | ||
}); | ||
|
||
wc.on('did-finish-load', () => { | ||
const title = wc.getTitle(); | ||
if (title === 'Window From Link') { | ||
process.exit(0); | ||
} | ||
}); | ||
}); | ||
|
||
createWindow(); | ||
}); |
11 changes: 11 additions & 0 deletions
11
spec-main/fixtures/apps/open-new-window-from-link/new-window-page.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'"> | ||
<title>Window From Link</title> | ||
</head> | ||
<body> | ||
I'm a window opened from a link! | ||
</body> | ||
</html> |
4 changes: 4 additions & 0 deletions
4
spec-main/fixtures/apps/open-new-window-from-link/package.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "electron-test-open-new-window-from-link", | ||
"main": "main.js" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
window.addEventListener('click', e => { | ||
console.log('click', e); | ||
}); |