Runs an expression in the page and returns its value, awaiting promises.
(sessionId, expression)
| 129 | |
| 130 | /** Runs an expression in the page and returns its value, awaiting promises. */ |
| 131 | async evaluate(sessionId, expression) { |
| 132 | const result = await this.send( |
| 133 | 'Runtime.evaluate', |
| 134 | { expression, returnByValue: true, awaitPromise: true }, |
| 135 | sessionId, |
| 136 | ); |
| 137 | if (result.exceptionDetails) { |
| 138 | throw new Error(result.exceptionDetails.exception?.description ?? 'page threw'); |
| 139 | } |
| 140 | return result.result.value; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | // --------------------------------------------------------------------------- |