Make executeJavaScript return a Promise so that caught errors can be sent to the caller
This commit is contained in:
parent
75b010ce63
commit
857e1da6a3
5 changed files with 59 additions and 7 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue