← Back to Discord Forum

how to get headers sent in playwright using APIRequestContext

Hello, I need to get the default headers defined in the API Request Context before the call for debugging purposes, how to do that? I did not find anything usefull. Looks that PW dont have support for this

This thread is trying to answer question "How to get the default headers defined in the API Request Context before the call for debugging purposes in Playwright?"

5 replies

@start_qa there is no direct built-in support to access the default headers defined in the API request context before making the actual API call

Is there any way to get the request headers post call? Sort of like a curl -v perhaps?

We've run into a situation where the response headers seem to indicate that the apiContext is calling the UI instead of the API URL. Would like to debug which URL is actually being called.

I've tried using the response.url() - Is this reporting the requested URL?

See the sample request and response below.

// assuming
// ui url: https://my.ui.url/ui <-- set as baseURL in playwright.config.ts
// api endpoint: https://my.api.url/api/test

const apiContext: APIRequestContext = playwright.request.newContext({
  baseURL: 'https://my.api.url/'
const response = await apiContext.get('/api/test');
console.log(response.url()) // gives https://my.ui.url/ui

BTW in reference to the original question I see that you call


to get the headers from the response. I assume that these are not what the OP needed?

Going to move this to a new question

You can set the "DEBUG=pw:api" env var, then you'll see exactly whats going in and out.

Related Discord Threads

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.