Skip to content

Using the "extraHeaders" option can break CSS/JS/Resource loading, as the headers are included on all requestsΒ #16676

@dcoffey-zengenti

Description

@dcoffey-zengenti

FAQ

URL

https://www.epa.ie/who-we-are/gaeilge/an-sceim-teanga/

What happened?

Some resources on the page are blocked due to a CORS error from allowed headers.

 {
        "method": "Network.loadingFailed",
        "params": {
          "requestId": "7416.49",
          "timestamp": 721073.514311,
          "type": "Font",
          "errorText": "net::ERR_FAILED",
          "canceled": false,
          "corsErrorStatus": {
            "corsError": "HeaderDisallowedByPreflightResponse",
            "failedParameter": "x-hide-preview-toolbar"
          }
        },
        "targetType": "page",
        "sessionId": "B88FA97ACC7C3B86A5265831AEA4C3FE"
      },

has been blocked by CORS policy: Request header field x-hide-preview-toolbar is not allowed by Access-Control-Allow-Headers in preflight response.

What did you expect?

Expected the header to only be added to my current page request rather than all subsequent requests.

What have you tried?

Patching:

if (headers) await session.sendCommand('Network.setExtraHTTPHeaders', { headers });

to:

if (headers) {
  // Use the Fetch protocol to only add headers to the main document requests.
  await session.sendCommand('Fetch.enable', {
    patterns: [{urlPattern: '*', resourceType: 'Document', requestStage: 'Request'}],
  });
  session.on('Fetch.requestPaused', async event => {
    await session.sendCommand('Fetch.continueRequest', {
      requestId: event.requestId,
      // Merge the extra headers with the existing headers and ensure value is a string.
      headers: Object.entries({...event.request.headers, ...headers}).map(([name, value]) => ({
          name,
          value: String(value),
        })),
    });
  });
}

How were you running Lighthouse?

node

Lighthouse Version

12.8.1

Chrome Version

139.0.7258.157

Node Version

22.18.0

OS

Windows

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions