Table of Contents
📖 1 minute read
Need to integrate with an API that has no documentation? Use Playwright to capture exactly what the browser sends, then replicate it.
The Approach
Open the web application in Playwright, perform the action you want to automate, and capture every network request:
const { chromium } = require('playwright');
const browser = await chromium.launch({ headless: false });
const page = await browser.newPage();
// Capture all requests
page.on('request', request => {
console.log(JSON.stringify({
url: request.url(),
method: request.method(),
headers: request.headers(),
postData: request.postData(),
}, null, 2));
});
await page.goto('https://app.example.com/login');
// Perform login, navigate, trigger the action you need
What You Get
Every header, every cookie, every POST body — exactly as the browser sends them. Copy these into your HTTP client (Guzzle, cURL, whatever) and you have a working integration.
Pro Tips
- Copy ALL headers — APIs sometimes check
Sec-Ch-Ua,Priority, and other browser-specific headers - Watch the auth flow — OAuth redirects, token exchanges, cookie chains are all visible
- Record, don’t guess — Even “documented” APIs sometimes behave differently than their docs say
Takeaway
When docs don’t exist (or lie), let the browser show you the truth. Playwright captures the exact HTTP conversation — just replicate it in your code.

Leave a Reply