What is the purpose of max-age in Cache-Control headers when using request.headersArray() in Playwright?


To use request.headersArray() in @playwright/test, you should know that it returns an array of all request HTTP headers, with header names not lower-cased. Headers with multiple entries appear multiple times in the array.

Regarding max-age, it's an optional parameter in the Cache-Control header of an HTTP response, specifying how long a cached resource remains fresh. When a browser receives a response with a max-age value, it caches the resource for that duration before making another request.

For example, consider this Cache-Control header: "Cache-Control: max-age=3600". It means the resource can be cached for up to one hour (3600 seconds) before it's considered stale and needs revalidation through another server request.

Here's a TypeScript example using @playwright/test to intercept a request and log the headers array:

import { test, expect } from '@playwright/test';

test('Log request headers array', async ({ page }) => {
  // Intercept requests
  await page.route('**/*', (route, request) => {
    // Log the headers array

    // Continue the request

  // Navigate to the website
  await page.goto('https://ray.run/');

In summary, request.headersArray() retrieves all headers associated with an HTTP request, while max-age is used in caching mechanisms to define how long resources should stay fresh before revalidation.

Thank you!
Was this helpful?
Still have questions?

If you still have questions, please ask a question and I will try to answer it.

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.