Skip to content

feat!: add onPage callback with ScenarioContext#221

Merged
be-next merged 1 commit intomainfrom
feat/onpage-callback-scenario-context
Mar 8, 2026
Merged

feat!: add onPage callback with ScenarioContext#221
be-next merged 1 commit intomainfrom
feat/onpage-callback-scenario-context

Conversation

@be-next
Copy link
Collaborator

@be-next be-next commented Mar 8, 2026

Summary

  • Add ScenarioContext type (scenarioName, workerIndex, iteration) and OnPageCallback type to src/core/model.ts
  • Add optional onPage parameter to evalScenario() — called after browser.newPage(), before action execution
  • Breaking change: refactor readYamlAndInterpret from positional args (yaml, browsers?, logger?) to options object (yaml, { browsers?, logger?, onPage? })
  • Re-export ScenarioContext and OnPageCallback from package entry point
  • Bump version to 2.0.0

Motivation

Kyara (the load testing tool) needs to attach Puppeteer event listeners (request, response, error, console) on each page with scenario-aware labels for Prometheus metrics. Currently, yaml-pptr manages the page lifecycle internally with no hook point. This PR enables callers to receive each Page with full execution context before actions run.

Test plan

  • New unit tests: onPage called with correct context (1 worker/1 iteration)
  • New unit tests: onPage called N×M times for N workers × M iterations
  • New unit tests: backward compatibility without onPage
  • New integration test: onPage propagated through readYamlAndInterpretevalScenario
  • All existing tests adapted to new options object signature
  • npm test — 44/44 passing
  • npm run build — clean compilation

🤖 Generated with Claude Code

Refactor readYamlAndInterpret to use an options object and add an onPage
callback that receives ScenarioContext (scenarioName, workerIndex,
iteration) after each browser.newPage(). This enables callers like Kyara
to attach event listeners with scenario-aware labels for Prometheus metrics.

BREAKING CHANGE: readYamlAndInterpret signature changed from
(yaml, browsers?, logger?) to (yaml, options?).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@be-next be-next merged commit 7c1c144 into main Mar 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant