Skip to content

Commit

Permalink
Merge pull request #70 from karthikuj/65-feature-add-support-to-run-c…
Browse files Browse the repository at this point in the history
…ustom-js

Adds support for executing custom scripts while authenticating
  • Loading branch information
karthikuj authored Jul 13, 2024
2 parents b720153 + b499231 commit 522b47c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ All notable changes to this project will be documented in this file.

## Unreleased

## [1.0.0] - 2024-07-13
### Added
- Multi-browser support
- Wait till `document.readyState` is equal to `complete`.
- Support to run custom JS while authenticating.

### Fixed
- `CrawlAction` element name bug.
Expand Down
24 changes: 24 additions & 0 deletions src/auth/authenticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ const fs = require('fs');
* The Extension class responsible for running the pptr auth recording.
*/
class Extension extends PuppeteerRunnerExtension {
/**
*
* @param {@puppeteer/replay.Step} step
* @param {Puppeteer.Page} page
*/
static executeScriptHandler = async (step, page) => {
if (Object.hasOwnProperty.call(step, 'parameters')) {
const parameters = step['parameters'];
if (parameters !== null && typeof parameters === 'object' && !Array.isArray(parameters)) {
if (Object.hasOwnProperty.call(parameters, 'target')) {
await page.evaluate(parameters['target']);
}
}
}
};

static customStepHandler = {
executeScript: this.executeScriptHandler,
};


/**
* This defines what is to be executed before all other steps.
* @param {@puppeteer/replay.UserFlow} flow
Expand All @@ -19,6 +40,9 @@ class Extension extends PuppeteerRunnerExtension {
* @param {@puppeteer/replay.UserFlow} flow
*/
async beforeEachStep(step, flow) {
if (step.type === 'customStep' && Object.hasOwnProperty.call(Extension.customStepHandler, step.name)) {
await Extension.customStepHandler[step.name](step, this.page);
}
await super.beforeEachStep(step, flow);
}

Expand Down

0 comments on commit 522b47c

Please sign in to comment.