From b30f8e13d89b8ce611afde44292ea82243b3a141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Black-Hole=EF=B8=8F?= Date: Tue, 25 Apr 2023 19:16:30 +0800 Subject: [PATCH] fix: webContents return type incorrect (#38111) fix: webContents return type incorrect (#38026) * fix: webContents type incorrect * fix: ci failed * fix: ci failed 2 --- docs/api/web-contents.md | 8 ++++---- spec/api-web-contents-spec.ts | 6 +++--- spec/chromium-spec.ts | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 203df2b1b33d9..fcc99a2d40de3 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -35,28 +35,28 @@ for all windows, webviews, opened devtools, and devtools extension background pa ### `webContents.getFocusedWebContents()` -Returns `WebContents` | null - The web contents that is focused in this application, otherwise +Returns `WebContents | null` - The web contents that is focused in this application, otherwise returns `null`. ### `webContents.fromId(id)` * `id` Integer -Returns `WebContents` | undefined - A WebContents instance with the given ID, or +Returns `WebContents | undefined` - A WebContents instance with the given ID, or `undefined` if there is no WebContents associated with the given ID. ### `webContents.fromFrame(frame)` * `frame` WebFrameMain -Returns `WebContents` | undefined - A WebContents instance with the given WebFrameMain, or +Returns `WebContents | undefined` - A WebContents instance with the given WebFrameMain, or `undefined` if there is no WebContents associated with the given WebFrameMain. ### `webContents.fromDevToolsTargetId(targetId)` * `targetId` string - The Chrome DevTools Protocol [TargetID](https://chromedevtools.github.io/devtools-protocol/tot/Target/#type-TargetID) associated with the WebContents instance. -Returns `WebContents` | undefined - A WebContents instance with the given TargetID, or +Returns `WebContents | undefined` - A WebContents instance with the given TargetID, or `undefined` if there is no WebContents associated with the given TargetID. When communicating with the [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/), diff --git a/spec/api-web-contents-spec.ts b/spec/api-web-contents-spec.ts index 7fabaf530a7b6..4b950374828d4 100644 --- a/spec/api-web-contents-spec.ts +++ b/spec/api-web-contents-spec.ts @@ -497,16 +497,16 @@ describe('webContents module', () => { testFn('returns the focused web contents', async () => { const w = new BrowserWindow({ show: true }); await w.loadFile(path.join(__dirname, 'fixtures', 'blank.html')); - expect(webContents.getFocusedWebContents().id).to.equal(w.webContents.id); + expect(webContents.getFocusedWebContents()?.id).to.equal(w.webContents.id); const devToolsOpened = emittedOnce(w.webContents, 'devtools-opened'); w.webContents.openDevTools(); await devToolsOpened; - expect(webContents.getFocusedWebContents().id).to.equal(w.webContents.devToolsWebContents!.id); + expect(webContents.getFocusedWebContents()?.id).to.equal(w.webContents.devToolsWebContents!.id); const devToolsClosed = emittedOnce(w.webContents, 'devtools-closed'); w.webContents.closeDevTools(); await devToolsClosed; - expect(webContents.getFocusedWebContents().id).to.equal(w.webContents.id); + expect(webContents.getFocusedWebContents()?.id).to.equal(w.webContents.id); }); it('does not crash when called on a detached dev tools window', async () => { diff --git a/spec/chromium-spec.ts b/spec/chromium-spec.ts index d3331b425bc89..d8e02350d8810 100644 --- a/spec/chromium-spec.ts +++ b/spec/chromium-spec.ts @@ -1954,7 +1954,7 @@ describe('chromium features', () => { await w1.loadFile(path.join(__dirname, 'fixtures', 'blank.html')); await w2.loadFile(path.join(__dirname, 'fixtures', 'blank.html')); await w3.loadFile(path.join(__dirname, 'fixtures', 'blank.html')); - expect(webContents.getFocusedWebContents().id).to.equal(w2.webContents.id); + expect(webContents.getFocusedWebContents()?.id).to.equal(w2.webContents.id); let focus = false; focus = await w1.webContents.executeJavaScript( 'document.hasFocus()'