docs: webFrameMain.fromId() can return undefined (#27068)
* docs: webFrameMain.fromId() can return undefined * docs: webFrameMain.fromId() can return undefined
This commit is contained in:
parent
c210956afb
commit
16c864a932
2 changed files with 18 additions and 17 deletions
|
@ -63,7 +63,8 @@ These methods can be accessed from the `webFrameMain` module:
|
||||||
instances (`frame.routingId`) and are also passed by frame
|
instances (`frame.routingId`) and are also passed by frame
|
||||||
specific `WebContents` navigation events (e.g. `did-frame-navigate`).
|
specific `WebContents` navigation events (e.g. `did-frame-navigate`).
|
||||||
|
|
||||||
Returns `WebFrameMain` - A frame with the given process and routing IDs.
|
Returns `WebFrameMain | undefined` - A frame with the given process and routing IDs,
|
||||||
|
or `undefined` if there is no WebFrameMain associated with the given IDs.
|
||||||
|
|
||||||
## Class: WebFrameMain
|
## Class: WebFrameMain
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import * as path from 'path';
|
||||||
import * as url from 'url';
|
import * as url from 'url';
|
||||||
import { BrowserWindow, WebFrameMain, webFrameMain } from 'electron/main';
|
import { BrowserWindow, WebFrameMain, webFrameMain } from 'electron/main';
|
||||||
import { closeAllWindows } from './window-helpers';
|
import { closeAllWindows } from './window-helpers';
|
||||||
import { emittedOnce } from './events-helpers';
|
import { emittedOnce, emittedNTimes } from './events-helpers';
|
||||||
import { AddressInfo } from 'net';
|
import { AddressInfo } from 'net';
|
||||||
|
|
||||||
describe('webFrameMain module', () => {
|
describe('webFrameMain module', () => {
|
||||||
|
@ -178,24 +178,24 @@ describe('webFrameMain module', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('webFrameMain.fromId can find each frame from navigation events', (done) => {
|
describe('webFrameMain.fromId', () => {
|
||||||
const w = new BrowserWindow({ show: false, webPreferences: { contextIsolation: true } });
|
it('returns undefined for unknown IDs', () => {
|
||||||
|
expect(webFrameMain.fromId(0, 0)).to.be.undefined();
|
||||||
|
});
|
||||||
|
|
||||||
w.loadFile(path.join(subframesPath, 'frame-with-frame-container.html'));
|
it('can find each frame from navigation events', async () => {
|
||||||
|
const w = new BrowserWindow({ show: false, webPreferences: { contextIsolation: true } });
|
||||||
let eventCount = 0;
|
|
||||||
w.webContents.on('did-frame-finish-load', (event, isMainFrame, frameProcessId, frameRoutingId) => {
|
|
||||||
const frame = webFrameMain.fromId(frameProcessId, frameRoutingId);
|
|
||||||
expect(frame).not.to.be.null();
|
|
||||||
expect(frame?.processId).to.be.equal(frameProcessId);
|
|
||||||
expect(frame?.routingId).to.be.equal(frameRoutingId);
|
|
||||||
expect(frame?.top === frame).to.be.equal(isMainFrame);
|
|
||||||
|
|
||||||
eventCount++;
|
|
||||||
|
|
||||||
// frame-with-frame-container.html, frame-with-frame.html, frame.html
|
// frame-with-frame-container.html, frame-with-frame.html, frame.html
|
||||||
if (eventCount === 3) {
|
const didFrameFinishLoad = emittedNTimes(w.webContents, 'did-frame-finish-load', 3);
|
||||||
done();
|
w.loadFile(path.join(subframesPath, 'frame-with-frame-container.html'));
|
||||||
|
|
||||||
|
for (const [, isMainFrame, frameProcessId, frameRoutingId] of await didFrameFinishLoad) {
|
||||||
|
const frame = webFrameMain.fromId(frameProcessId, frameRoutingId);
|
||||||
|
expect(frame).not.to.be.null();
|
||||||
|
expect(frame?.processId).to.be.equal(frameProcessId);
|
||||||
|
expect(frame?.routingId).to.be.equal(frameRoutingId);
|
||||||
|
expect(frame?.top === frame).to.be.equal(isMainFrame);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue