feat: add will-frame-navigate
event (#34418)
* feat: add will-navigate-in-frame event to webContents * docs: add documentation for webview will-frame-navigate event * feat: Eliminate isInPlace argument from will-frame-navigate event * fix: Fire will-frame-navigate before will-navigate * feat: send will-frame-navigate with a WebFrameMain in the event details * docs: Update WebContents docs for new API signature * feat: Add custom event forwarding for <webview> will-frame-navigate * fix: wrap WebFrameMain so it can be sent as an event * test: update webContents and <webview> tests to match new signatures * chore: undo unnecessary change * fix: don't switch will-navigate to use EmitNavigationEventDetails * test: clean up will-navigate and will-frame-navigate tests for <webview> * chore: apply lint fixes * chore: move GetRenderFrameHost helper into anonymous namespace * docs: auto-generate WillFrameNavigateDetails rather than defining it manually * test: Update <webview> tests to actually pass under new spec runner * docs: Add section explaining relationship between various nav events * test: Add some tests to ensure navigation event order doesn't silently change * test: Always monitor all nav events to ensure unexpected ones don't fire * test: Add test to verify in-page navigation event order * feat: Change to new style where extra params are exposed as event props * fix: Remove unused EmitNavigationEventDetails * fix: Update tests to use new async helpers * docs: Rename and reorder sections documenting navigation events --------- Co-authored-by: Milan Burda <milan.burda@gmail.com>
This commit is contained in:
parent
2e1f803f37
commit
2b9dae4b06
8 changed files with 540 additions and 14 deletions
|
@ -1480,7 +1480,7 @@ describe('<webview> tag', function () {
|
|||
});
|
||||
|
||||
describe('will-navigate event', () => {
|
||||
it('emits when a url that leads to outside of the page is clicked', async () => {
|
||||
it('emits when a url that leads to outside of the page is loaded', async () => {
|
||||
const { url } = await loadWebViewAndWaitForEvent(w, {
|
||||
src: `file://${fixtures}/pages/webview-will-navigate.html`
|
||||
}, 'will-navigate');
|
||||
|
@ -1489,6 +1489,47 @@ describe('<webview> tag', function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe('will-frame-navigate event', () => {
|
||||
it('emits when a link that leads to outside of the page is loaded', async () => {
|
||||
const { url, isMainFrame } = await loadWebViewAndWaitForEvent(w, {
|
||||
src: `file://${fixtures}/pages/webview-will-navigate.html`
|
||||
}, 'will-frame-navigate');
|
||||
expect(url).to.equal('http://host/');
|
||||
expect(isMainFrame).to.be.true();
|
||||
});
|
||||
|
||||
it('emits when a link within an iframe, which leads to outside of the page, is loaded', async () => {
|
||||
await loadWebView(w, {
|
||||
src: `file://${fixtures}/pages/webview-will-navigate-in-frame.html`,
|
||||
nodeIntegration: ''
|
||||
});
|
||||
|
||||
const { url, frameProcessId, frameRoutingId } = await w.executeJavaScript(`
|
||||
new Promise((resolve, reject) => {
|
||||
let hasFrameNavigatedOnce = false;
|
||||
const webview = document.getElementById('webview');
|
||||
webview.addEventListener('will-frame-navigate', ({url, isMainFrame, frameProcessId, frameRoutingId}) => {
|
||||
if (isMainFrame) return;
|
||||
if (hasFrameNavigatedOnce) resolve({
|
||||
url,
|
||||
isMainFrame,
|
||||
frameProcessId,
|
||||
frameRoutingId,
|
||||
});
|
||||
|
||||
// First navigation is the initial iframe load within the <webview>
|
||||
hasFrameNavigatedOnce = true;
|
||||
});
|
||||
webview.executeJavaScript('loadSubframe()');
|
||||
});
|
||||
`);
|
||||
|
||||
expect(url).to.equal('http://host/');
|
||||
expect(frameProcessId).to.be.a('number');
|
||||
expect(frameRoutingId).to.be.a('number');
|
||||
});
|
||||
});
|
||||
|
||||
describe('did-navigate event', () => {
|
||||
it('emits when a url that leads to outside of the page is clicked', async () => {
|
||||
const pageUrl = url.pathToFileURL(path.join(fixtures, 'pages', 'webview-will-navigate.html')).toString();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue