-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added the scenario option `config.options.proxyUrls`. - Added action `evaluate`. - Added strategy `evaluate` in the action `collectData`.
- Loading branch information
Showing
6 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { AbstractAction } from './abstract-action.mjs'; | ||
|
||
export class Evaluate extends AbstractAction { | ||
constructor() { | ||
super('evaluate'); | ||
} | ||
|
||
*_doValidateOptions({ options }) { | ||
if (!('script' in options) || 'string' !== typeof options.script || '' === options.script) { | ||
yield 'the option "script" is required and must be a non empty string'; | ||
} | ||
|
||
if ('failOnError' in options && 'boolean' !== typeof options.failOnError) { | ||
yield 'the optional option "failOnError" must be a bool'; | ||
} | ||
|
||
if ('failOnFalsyReturn' in options && 'boolean' !== typeof options.failOnFalsyReturn) { | ||
yield 'the optional option "failFalsyReturn" must be a bool'; | ||
} | ||
} | ||
|
||
async execute(options, { page }) { | ||
const failOnError = 'failOnError' in options ? options.failOnError : true; | ||
const failOnFalsyReturn = 'failOnFalsyReturn' in options ? options.failOnFalsyReturn : false; | ||
let hasError = false; | ||
let result; | ||
|
||
try { | ||
result = await page.evaluate(options.script); | ||
} catch (err) { | ||
if (failOnError) { | ||
if (!err.message.startsWith('Evaluation failed:')) { | ||
err.message = `Evaluation failed: ${err.message}`; | ||
} | ||
|
||
throw err; | ||
} | ||
|
||
hasError = true; | ||
} | ||
|
||
if (failOnFalsyReturn && !hasError && !result) { | ||
throw new Error(`Evaluation failed: Script (${options.script}) returned a falsy result.`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters