The Simplest Way to Make Netlify Edge Functions and Playwright Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams use netlify edge functions and playwright to test code at the network edge. Playwright runs browser tests while edge code handles routing, headers, and user checks. This workflow catches routing bugs before users see them in production. Developers can test geo-routing, header rules, and login flows in one step. Good tests need fast feedback and strict rules for test keys. How netlify edge functions and playwright pass data and keys Playwright starts a real browser and sends web request

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.

Teams use netlify edge functions and playwright to test code at the network edge. Playwright runs browser tests while edge code handles routing, headers, and user checks.

This workflow catches routing bugs before users see them in production. Developers can test geo-routing, header rules, and login flows in one step. Good tests need fast feedback and strict rules for test keys.

How netlify edge functions and playwright pass data and keys

Playwright starts a real browser and sends web requests to your test site. The edge function catches each request before it hits the main web server. The edge code reads headers, cookies, and the user location from the request.

Next, the edge function checks if the request has a valid session token. It can change the page response, rewrite the URL, or block the user. Playwright then reads the final page and checks that the right content loaded.

To run these checks, Playwright needs a way to log in as a user. Teams often store test tokens or secret keys in their continuous integration runner. Playwright reads these keys and puts them into browser headers or cookies. The edge function checks those headers against a secret key stored in the platform. When both keys match, the edge code lets the test browser pass through. This flow lets teams test protected routes without typing passwords on every run.

Common failure modes and how to scope roles

Many teams fail by using one shared admin account for all browser tests. If that shared token leaks in a test log, attackers gain wide access. Shared accounts also make it hard to see which test broke a staging database.

Broad tokens cause another big problem during edge testing. Developers often give the test runner full read and write permissions across all services. A bug in a test script can then delete real data by mistake. Unlogged queries from edge functions also hide the root cause of failed tests. When an edge script calls an internal API and fails, teams need clear logs.

Right to Erasure Implementation + Cloud Functions IAM: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

You can fix these risks by scoping roles to the smallest needed task. Create separate test accounts for each role your app uses. Give one test user read-only rights and another user basic write rights. Set up your network paths so staging edge functions only reach staging databases. Never let a preview build talk to a live production service. Rotate your test secrets often and clear out old preview builds right away.

Best practices for local and preview testing

Running edge code on a local machine speeds up daily work. Developers can start a local server that mimics the cloud edge network. Playwright then points its browser at the local port to run fast checks. This setup finds broken header rules before the team pushes code to a branch.

Once the local test passes, the developer pushes the code to a git branch. The platform builds a unique preview URL that runs the new edge code. The continuous integration runner then starts Playwright and points it at that preview URL. Make sure your preview builds use mock data or isolated test databases. Mask sensitive fields like emails, phone numbers, and card numbers in your test results. Data masking rewrites matched fields in results so logs stay clean and safe.

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

How does Playwright test geo-routing in edge functions?

Playwright can send custom headers or mock locations during a browser test. Your edge code reads those test headers to simulate users from different countries.

Should edge tests use production API keys?

No, edge tests should never use live production keys or touch live data. Always use scoped staging keys with strict limits for all automated browser tests.

Why do edge function tests fail only in preview builds?

Preview builds often miss secret keys that exist in your local setup. Check that your preview build has the right keys and network rules set up.

The query runs. The emails stay hidden.