How to Get the HTTP Method of a Puppeteer Request
Read a Puppeteer request’s HTTP method with `request.method()`. See how to log requests, wait for a specific method, and avoid common interception pitfalls.
Call request.method() on Puppeteer’s HTTPRequest object. The page’s request event gives you that object whenever the page issues a request:
page.on('request', request => {
console.log(request.method());
});
You do not need request interception just to read the method. Use Puppeteer’s HTTPRequest API for the method accessor and Page.waitForRequest() when you need to wait for a matching request.
Log request methods during navigation
Register the listener before navigation or before the action that triggers the request, so the request is not missed. This runnable example prints each method and URL:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({ headless: true });
try {
const page = await browser.newPage();
page.on('request', request => {
console.log(request.method(), request.url());
});
await page.goto('https://example.com', { waitUntil: 'domcontentloaded' });
} finally {
await browser.close();
}
})();
The callback receives an HTTPRequest. Its method() accessor returns the HTTP method, such as GET or POST. This listener observes requests; it does not modify them.
Check for a particular method
Compare the returned method to the uppercase method name:
page.on('request', request => {
if (request.method() === 'POST') {
console.log('POST request:', request.url());
}
});
Keep the listener registered before the operation that sends the POST request. For a request triggered by a button, attach the listener first, then click the button.
Wait for a matching request
Use waitForRequest() when your next step depends on a specific request. It resolves to the matching HTTPRequest:
const requestPromise = page.waitForRequest(
request => request.url().includes('/api/') && request.method() === 'POST',
{ timeout: 10000 }
);
await page.click('#submit');
const request = await requestPromise;
console.log(request.method(), request.url());
Start waiting before the click to avoid a race. The predicate can check both URL and method so that an unrelated request does not satisfy the wait. The timeout is in milliseconds; choose a value appropriate to the page and fail clearly if the expected action does not send a request.
Complete script for a POST request
This example serves a local page with a button that sends a POST request, then waits for and reports that request. Save as inspect-post.js and run it in a Node.js project with Puppeteer installed:
const http = require('node:http');
const puppeteer = require('puppeteer');
(async () => {
const server = http.createServer((req, res) => {
if (req.url === '/') {
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' });
res.end('<button id="send">Send</button><script>document.querySelector("#send").onclick=()=>fetch("/api/submit",{method:"POST",body:"hello"})</script>');
return;
}
if (req.url === '/api/submit' && req.method === 'POST') {
res.writeHead(204);
res.end();
return;
}
res.writeHead(404);
res.end('Not found');
});
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
const address = server.address();
const url = `http://127.0.0.1:${address.port}/`;
let browser;
try {
browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.goto(url);
const requestPromise = page.waitForRequest(
request => request.url().endsWith('/api/submit') && request.method() === 'POST'
);
await page.click('#send');
const request = await requestPromise;
console.log('Method:', request.method());
console.log('URL:', request.url());
} finally {
if (browser) await browser.close();
await new Promise(resolve => server.close(resolve));
}
})();
Install Puppeteer in the project before running the script. The server uses an ephemeral local port and closes both the browser and server even if the inspection fails.
Do you need request interception?
No. The request event is sufficient for observation. page.setRequestInterception(true) is for changing how requests proceed, such as aborting, continuing, or fulfilling them. Once interception is enabled, requests pause until a handler resolves them or the browser serves them from cache. An unresolved intercepted request can make page loading hang.
If you do intercept requests, resolve each one appropriately. When more than one handler may handle an intercepted request, check isInterceptResolutionHandled() before acting; see the Puppeteer request interception guide.
Request events and edge cases
- HTTP status is separate from request failure. A 404 or 503 can still be a completed HTTP transaction and produce
requestfinished.requestfailedsignals that execution failed, not simply that the response status was non-2xx. - Redirects create multiple request objects. The original request finishes and a new request is issued for the redirected URL. Inspect the particular request whose method and URL matter.
- Request bodies are separate. Read the method with
method(). Body retrieval is a different API concern; the current HTTPRequest reference markspostData()deprecated in favor offetchPostData(). - Register early. A listener or wait added after navigation or after a fast action may miss the request.
- Match narrowly. Pages issue requests for scripts, images, analytics, and other resources. Include a URL or other identifying condition in a wait predicate.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The callback never runs | The listener was attached after the request, or the action did not issue one. | Attach the listener before navigation or the action. Confirm that the page action actually sends a network request. |
waitForRequest() times out |
The URL or method predicate does not match, the action failed, or the wait started too late. | Start the wait before triggering the action. Log all requests temporarily and loosen the predicate to identify the actual URL and method. |
| The page hangs after enabling interception | An intercepted request was left unresolved. | Continue, abort, or respond to every intercepted request, and account for other handlers resolving it first. |
| A 404 appears as finished rather than failed | HTTP error status and network execution failure are different conditions. | Inspect the response status for HTTP errors; use request failure events for execution failures. |
| A redirected request appears more than once | Each redirect hop is represented by a request object. | Inspect each event’s URL and method and identify the hop you need. |
Performance, reliability, and cost
Reading method() in an existing request listener is lightweight and does not require extra browser interception. Keep logging focused on the methods and URLs you need; recording every request can produce noisy output on asset-heavy pages. For reliable waits, register before the triggering action and use a specific predicate plus a finite timeout. Puppeteer’s request observation runs in your browser automation process, so account for the browser runtime and infrastructure in your own application costs.
Puppeteer’s current API documentation consulted for this guide is version 25.12.0. If behavior differs in your project, check the API reference for the Puppeteer version installed there.
Or skip the browser setup
If your goal is to inspect how a page looks rather than inspect its individual network requests, ScreenshotNeo can return a screenshot or PDF with one API request. See the ScreenshotNeo docs for the API and options.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo accepts cookie and consent banners like a visitor, then removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server gives AI agents tools to take screenshots, get page information, and capture PDFs. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.
Sign up free for 1,000 screenshots a month, no card required.
FAQ
Does request.method() return uppercase text?
Use the method string it returns directly; common values in the API documentation include GET and POST. Compare against the expected method string.
Can I get the method from a response?
The method belongs to the request. Read it from the HTTPRequest object provided by the request event or returned by waitForRequest().
Is method inspection limited to navigation requests?
No. The page request event reports requests issued by the page, including requests triggered by page actions. Attach the listener before the action you want to observe.


