The Simplest Way to Make Playwright and Step Functions Work Like They Should
Pairing playwright and step functions lets teams run browser tests and jobs in clear stages. Step Functions starts each step and tracks states while Playwright drives the web browser. This setup helps teams run end-to-end checks, scrape pages, and fill out web forms. You get retry rules from the state machine and browser actions from the test tool. When one browser step fails, the state machine catches the error and decides what happens next. Teams do not need to write custom retry loops inside
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
Pairing playwright and step functions lets teams run browser tests and jobs in clear stages. Step Functions starts each step and tracks states while Playwright drives the web browser.
This setup helps teams run end-to-end checks, scrape pages, and fill out web forms. You get retry rules from the state machine and browser actions from the test tool. When one browser step fails, the state machine catches the error and decides what happens next. Teams do not need to write custom retry loops inside their browser scripts.
How playwright and step functions pass data and roles
A state machine needs a way to start the browser runner and read results. Most teams run the browser inside a cloud function or a container task. The state machine calls that task and passes a small JSON payload as input. That input tells the browser which web page to open and what actions to take.
Identity and roles control every part of this handoff between the two tools. The state machine uses an execution role that allows it to start the browser task. The browser task then uses its own task role to read secrets or save files. Keeping these two roles separate stops the workflow from having too much power.
Data flows back to the state machine once the browser finishes its job. The browser script writes a small status message and sends it back as output. If the browser takes screenshots or makes trace files, it saves them to object storage. It then sends the storage file path back to the state machine in the JSON output. Passing file paths instead of raw files keeps state payloads small and fast.
Common failure modes and how to scope access
Many teams run into trouble when they share one log-in account across all browser jobs. If fifty workflows log into a web app with the same user, locks happen fast. You also lose track of which workflow changed data inside the target web app. Another common mistake is using broad cloud tokens that can read every secret in the account.
Unlogged browser actions also create big blind spots during a security review. A state machine logs when a task starts and stops, but not what the browser clicked. If a browser script edits a live settings page, you need a clear record of that action. You must also watch out for personal data like emails or phone numbers on screen. Masking rules can rewrite matched fields like card numbers or national IDs in results.
Right to Erasure Implementation + Cloud Functions IAM: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
To fix these risks, scope every role and network path down to the bare minimum. Give each workflow its own cloud role that only reads the single secret it needs. Put the browser tasks in a private subnet that only reaches approved web hosts. Set strict timeouts on both the browser script and the state machine step. When a page hangs, the state machine will stop the task and alert your team.
Designing clean retries and error paths
Browser tasks fail for many reasons that have nothing to do with bad code. A slow network link or a late pop-up box can break a step. If you retry the whole state machine from the start, you waste time and compute money.
Break your browser work into small, single-purpose steps inside the workflow. One step can check if the site is up, and the next can run the browser task. Set the state machine to retry only on transient network errors, not on bad log-in keys. Route failed runs to a cleanup step that saves the error log for your team.
Check database and API queries on the wire
Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.
Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.
Frequently asked questions
Should I run Playwright in a cloud function or a container task?
Use a cloud function for short browser checks that finish in a few minutes. Pick a container task for long jobs or suites that need more memory and CPU.
How do I handle web app log-in secrets in this setup?
Store log-in keys in a cloud secret store and restrict the task role to one secret. Fetch the secret inside the browser task right before the log-in step runs.
Why do my state machine payloads fail when browser tests return results?
State machines have strict size limits on the JSON data passed between steps. Save large files like screenshots to object storage and pass only the file link.
Related guides
In this post