diff --git a/spec/api-browser-window-spec.ts b/spec/api-browser-window-spec.ts index 540ad42d14e..5f0466b16c0 100644 --- a/spec/api-browser-window-spec.ts +++ b/spec/api-browser-window-spec.ts @@ -2343,7 +2343,7 @@ describe('BrowserWindow module', () => { expect(w.isAlwaysOnTop()).to.be.false(); expect(c.isAlwaysOnTop()).to.be.true('child is not always on top'); - expect((c as any)._getAlwaysOnTopLevel()).to.equal('screen-saver'); + expect(c._getAlwaysOnTopLevel()).to.equal('screen-saver'); }); }); diff --git a/spec/api-debugger-spec.ts b/spec/api-debugger-spec.ts index 057f39e4184..1e63bd9c2a9 100644 --- a/spec/api-debugger-spec.ts +++ b/spec/api-debugger-spec.ts @@ -64,7 +64,7 @@ describe('debugger module', () => { }); await detach; expect(w.webContents.debugger.isAttached()).to.be.false(); - expect((w as any).devToolsWebContents.isDestroyed()).to.be.false(); + expect(w.devToolsWebContents.isDestroyed()).to.be.false(); }); }); @@ -119,9 +119,9 @@ describe('debugger module', () => { w.webContents.debugger.sendCommand('Console.enable'); const [,, params] = await message; w.webContents.debugger.detach(); - expect((params as any).message.level).to.equal('log'); - expect((params as any).message.url).to.equal(url); - expect((params as any).message.text).to.equal('a'); + expect(params.message.level).to.equal('log'); + expect(params.message.url).to.equal(url); + expect(params.message.text).to.equal('a'); }); it('returns error message when command fails', async () => { diff --git a/spec/api-ipc-spec.ts b/spec/api-ipc-spec.ts index 57491ed5708..873511b6ea3 100644 --- a/spec/api-ipc-spec.ts +++ b/spec/api-ipc-spec.ts @@ -239,7 +239,7 @@ describe('ipc module', () => { const p = once(ipcMain, 'port'); await w.webContents.executeJavaScript(`(${function () { const channel = new MessageChannel(); - (channel.port2 as any).onmessage = (ev: any) => { + channel.port2.onmessage = (ev: any) => { channel.port2.postMessage(ev.data * 2); }; require('electron').ipcRenderer.postMessage('port', '', [channel.port1]); @@ -280,7 +280,7 @@ describe('ipc module', () => { w2.loadURL('about:blank'); w1.webContents.executeJavaScript(`(${function () { const channel = new MessageChannel(); - (channel.port2 as any).onmessage = (ev: any) => { + channel.port2.onmessage = (ev: any) => { require('electron').ipcRenderer.send('message received', ev.data); }; require('electron').ipcRenderer.postMessage('port', '', [channel.port1]); @@ -306,7 +306,7 @@ describe('ipc module', () => { ipcRenderer.on('port', e => { const [port] = e.ports; port.start(); - (port as any).onclose = () => { + port.onclose = () => { ipcRenderer.send('closed'); }; }); @@ -322,9 +322,9 @@ describe('ipc module', () => { w.loadURL('about:blank'); await w.webContents.executeJavaScript(`(${async function () { const { port2 } = new MessageChannel(); - await new Promise(resolve => { + await new Promise(resolve => { port2.start(); - (port2 as any).onclose = resolve; + port2.onclose = resolve; process._linkedBinding('electron_common_v8_util').requestGarbageCollectionForTesting(); }); }})()`); @@ -336,9 +336,9 @@ describe('ipc module', () => { ipcMain.once('do-a-gc', () => v8Util.requestGarbageCollectionForTesting()); await w.webContents.executeJavaScript(`(${async function () { const { port1, port2 } = new MessageChannel(); - await new Promise(resolve => { + await new Promise(resolve => { port2.start(); - (port2 as any).onclose = resolve; + port2.onclose = resolve; require('electron').ipcRenderer.postMessage('nobody-listening', null, [port1]); require('electron').ipcRenderer.send('do-a-gc'); }); diff --git a/spec/api-web-contents-spec.ts b/spec/api-web-contents-spec.ts index 089523c9537..dc9b2e6161a 100644 --- a/spec/api-web-contents-spec.ts +++ b/spec/api-web-contents-spec.ts @@ -1911,7 +1911,7 @@ describe('webContents module', () => { it('does not crash when called via BrowserWindow', () => { const w = new BrowserWindow({ show: false }); - (w as any).setBackgroundThrottling(true); + w.setBackgroundThrottling(true); }); it('does not crash when disallowing', () => { @@ -1946,11 +1946,11 @@ describe('webContents module', () => { it('works via BrowserWindow', () => { const w = new BrowserWindow({ show: false }); - (w as any).setBackgroundThrottling(false); - expect((w as any).getBackgroundThrottling()).to.equal(false); + w.setBackgroundThrottling(false); + expect(w.getBackgroundThrottling()).to.equal(false); - (w as any).setBackgroundThrottling(true); - expect((w as any).getBackgroundThrottling()).to.equal(true); + w.setBackgroundThrottling(true); + expect(w.getBackgroundThrottling()).to.equal(true); }); }); diff --git a/spec/chromium-spec.ts b/spec/chromium-spec.ts index 9216038dfdf..f39526df5ae 100644 --- a/spec/chromium-spec.ts +++ b/spec/chromium-spec.ts @@ -2012,13 +2012,13 @@ describe('chromium features', () => { const w = new BrowserWindow({ show: false }); await w.loadFile(path.join(fixturesPath, 'pages', 'blank.html')); // History should have current page by now. - expect((w.webContents as any).length()).to.equal(1); + expect(w.webContents.length()).to.equal(1); const waitCommit = once(w.webContents, 'navigation-entry-committed'); w.webContents.executeJavaScript('window.history.pushState({}, "")'); await waitCommit; // Initial page + pushed state. - expect((w.webContents as any).length()).to.equal(2); + expect(w.webContents.length()).to.equal(2); }); }); @@ -2038,7 +2038,7 @@ describe('chromium features', () => { once(w.webContents, 'did-navigate-in-page') ]); - (w.webContents as any).once('navigation-entry-committed', () => { + w.webContents.once('navigation-entry-committed' as any, () => { expect.fail('Unexpected navigation-entry-committed'); }); w.webContents.once('did-navigate-in-page', () => { @@ -2046,7 +2046,7 @@ describe('chromium features', () => { }); await w.webContents.mainFrame.frames[0].executeJavaScript('window.history.back()'); expect(await w.webContents.executeJavaScript('window.history.state')).to.equal(1); - expect((w.webContents as any).getActiveIndex()).to.equal(1); + expect(w.webContents.getActiveIndex()).to.equal(1); }); }); }); diff --git a/typings/internal-ambient.d.ts b/typings/internal-ambient.d.ts index 26cff6bc760..1805f58de46 100644 --- a/typings/internal-ambient.d.ts +++ b/typings/internal-ambient.d.ts @@ -291,6 +291,12 @@ declare interface Window { trustedTypes: TrustedTypePolicyFactory; } +// https://github.com/electron/electron/blob/main/docs/tutorial/message-ports.md#extension-close-event + +interface MessagePort { + onclose: () => void; +} + // https://w3c.github.io/webappsec-trusted-types/dist/spec/#trusted-types type TrustedHTML = string; diff --git a/typings/internal-electron.d.ts b/typings/internal-electron.d.ts index af6be190c34..c21a42aece4 100644 --- a/typings/internal-electron.d.ts +++ b/typings/internal-electron.d.ts @@ -32,6 +32,8 @@ declare namespace Electron { _setEscapeTouchBarItem: (item: TouchBarItemType | {}) => void; _refreshTouchBarItem: (itemID: string) => void; _getWindowButtonVisibility: () => boolean; + _getAlwaysOnTopLevel: () => string; + devToolsWebContents: WebContents; frameName: string; on(event: '-touch-bar-interaction', listener: (event: Event, itemID: string, details: any) => void): this; removeListener(event: '-touch-bar-interaction', listener: (event: Event, itemID: string, details: any) => void): this;