fix: webContents return type incorrect (#38026)

* fix: webContents type incorrect

* fix: ci failed

* fix: ci failed 2
This commit is contained in:
Black-Hole️ 2023-04-24 22:28:21 +08:00 коммит произвёл GitHub
Родитель b626be5e33
Коммит 141f65b291
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 8 добавлений и 8 удалений

Просмотреть файл

@ -65,28 +65,28 @@ for all windows, webviews, opened devtools, and devtools extension background pa
### `webContents.getFocusedWebContents()` ### `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`. returns `null`.
### `webContents.fromId(id)` ### `webContents.fromId(id)`
* `id` Integer * `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. `undefined` if there is no WebContents associated with the given ID.
### `webContents.fromFrame(frame)` ### `webContents.fromFrame(frame)`
* `frame` WebFrameMain * `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. `undefined` if there is no WebContents associated with the given WebFrameMain.
### `webContents.fromDevToolsTargetId(targetId)` ### `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. * `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. `undefined` if there is no WebContents associated with the given TargetID.
When communicating with the [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/), When communicating with the [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/),

Просмотреть файл

@ -492,16 +492,16 @@ describe('webContents module', () => {
ifit(!(process.platform === 'win32' && process.arch === 'arm64'))('returns the focused web contents', async () => { ifit(!(process.platform === 'win32' && process.arch === 'arm64'))('returns the focused web contents', async () => {
const w = new BrowserWindow({ show: true }); const w = new BrowserWindow({ show: true });
await w.loadFile(path.join(__dirname, 'fixtures', 'blank.html')); 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 = once(w.webContents, 'devtools-opened'); const devToolsOpened = once(w.webContents, 'devtools-opened');
w.webContents.openDevTools(); w.webContents.openDevTools();
await devToolsOpened; await devToolsOpened;
expect(webContents.getFocusedWebContents().id).to.equal(w.webContents.devToolsWebContents!.id); expect(webContents.getFocusedWebContents()?.id).to.equal(w.webContents.devToolsWebContents!.id);
const devToolsClosed = once(w.webContents, 'devtools-closed'); const devToolsClosed = once(w.webContents, 'devtools-closed');
w.webContents.closeDevTools(); w.webContents.closeDevTools();
await devToolsClosed; 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 () => { it('does not crash when called on a detached dev tools window', async () => {

Просмотреть файл

@ -1945,7 +1945,7 @@ describe('chromium features', () => {
await w1.loadFile(path.join(__dirname, 'fixtures', 'blank.html')); await w1.loadFile(path.join(__dirname, 'fixtures', 'blank.html'));
await w2.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')); 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; let focus = false;
focus = await w1.webContents.executeJavaScript( focus = await w1.webContents.executeJavaScript(
'document.hasFocus()' 'document.hasFocus()'