mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat: worker convenience methods (#2677)
This patch: - adds `worker.evaluate` and `worker.evaluateHandle` methods as a shortcut to their execution context equivalents. - makes the error messages a bit nicer when interacting with a closed worker (as opposed to a closed page). - moves the worker tests into their own spec file.
This commit is contained in:
committed by
Andrey Lushnikov
parent
3e82a54fd1
commit
2ff0adcad8
@@ -53,6 +53,24 @@ class Worker extends EventEmitter {
|
||||
async executionContext() {
|
||||
return this._executionContextPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {function()|string} pageFunction
|
||||
* @param {!Array<*>} args
|
||||
* @return {!Promise<*>}
|
||||
*/
|
||||
async evaluate(pageFunction, ...args) {
|
||||
return (await this._executionContextPromise).evaluate(pageFunction, ...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {function()|string} pageFunction
|
||||
* @param {!Array<*>} args
|
||||
* @return {!Promise<!JSHandle>}
|
||||
*/
|
||||
async evaluateHandle(pageFunction, ...args) {
|
||||
return (await this._executionContextPromise).evaluateHandle(pageFunction, ...args);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Worker;
|
||||
|
||||
Reference in New Issue
Block a user