feat: add webContents.close() (#35509)

* feat: add webContents.close()

* update docs, add test for beforeunload override

* Update web-contents.md
This commit is contained in:
Jeremy Rose 2022-09-16 16:22:59 -07:00 committed by GitHub
parent 994834d25a
commit eebf34cc6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 110 additions and 1 deletions

View file

@ -934,6 +934,21 @@ Returns `string` - The title of the current web page.
Returns `boolean` - Whether the web page is destroyed.
#### `contents.close([opts])`
* `opts` Object (optional)
* `waitForBeforeUnload` boolean - if true, fire the `beforeunload` event
before closing the page. If the page prevents the unload, the WebContents
will not be closed. The [`will-prevent-unload`](#event-will-prevent-unload)
will be fired if the page requests prevention of unload.
Closes the page, as if the web content had called `window.close()`.
If the page is successfully closed (i.e. the unload is not prevented by the
page, or `waitForBeforeUnload` is false or unspecified), the WebContents will
be destroyed and no longer usable. The [`destroyed`](#event-destroyed) event
will be emitted.
#### `contents.focus()`
Focuses the web page.