mirror of
https://github.com/electron/electron.git
synced 2026-05-02 03:00:22 -04:00
Make executeJavaScript return a Promise so that caught errors can be sent to the caller
This commit is contained in:
committed by
Kevin Sawicki
parent
75b010ce63
commit
857e1da6a3
@@ -620,12 +620,26 @@ Injects CSS into the current web page.
|
||||
* `callback` Function (optional) - Called after script has been executed.
|
||||
* `result` Any
|
||||
|
||||
Returns `Promise` - A promise that resolves with the result of the executed code
|
||||
or is rejected if the result of the code is a rejected promise
|
||||
|
||||
Evaluates `code` in page.
|
||||
|
||||
In the browser window some HTML APIs like `requestFullScreen` can only be
|
||||
invoked by a gesture from the user. Setting `userGesture` to `true` will remove
|
||||
this limitation.
|
||||
|
||||
If the result of the executed code is a promise the callback result will be the
|
||||
resolved value of the promise. We recommend that you use the returned Promise
|
||||
to handle code that results in a Promise.
|
||||
|
||||
```js
|
||||
contents.executeJavaScript('fetch("https://jsonplaceholder.typicode.com/users/1").then(resp => resp.json())', true)
|
||||
.then((result) => {
|
||||
console.log(result) // Will be the JSON object from the fetch call
|
||||
})
|
||||
```
|
||||
|
||||
#### `contents.setAudioMuted(muted)`
|
||||
|
||||
* `muted` Boolean
|
||||
|
||||
Reference in New Issue
Block a user