Skip to content

Conversation

AgnesToulet
Copy link
Contributor

It seems that page.on('request', ...) isn't triggered on EVERY request so adding the headers for every request and removing them here wasn't working for some requests.

This is achieving the same result, the other way around, only adding headers for requests we are sure we should add them.

@AgnesToulet AgnesToulet force-pushed the tracing/fix-headers branch from b156230 to b457858 Compare May 13, 2025 15:24
Copy link

@nmarrs nmarrs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

await page.setExtraHTTPHeaders(options.headers as any);
if (options.headers && options.headers['Accept-Language']) {
const headers = { 'Accept-Language': options.headers['Accept-Language'] };
this.log.debug(`Setting extra HTTP headers for page`, 'headers', headers);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to keep these debug logs for future troubleshooting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't add this one but yes I think it can be interesting for troubleshooting.

@nmarrs nmarrs requested a review from lucychen-grafana May 13, 2025 15:31
@evictorero evictorero requested a review from Copilot May 13, 2025 15:39
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses a CORS issue by switching the approach from removing headers on certain requests to only adding tracing headers when appropriate. The main changes include passing header options to page listeners in reusable, clustered, and browser modules, updating the logic for adding tracing headers, and refining the extra HTTP headers setup.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/browser/reusable.ts Updated calls to addPageListeners to pass the headers from options.
src/browser/clustered.ts Similar updates to pass header options to addPageListeners.
src/browser/browser.ts Modified addPageListeners and tracing header logic to only add headers when conditions apply, and refined the HTTP header setup.
Comments suppressed due to low confidence (1)

src/browser/browser.ts:630

  • Update the error message in the catch block to reflect that the code is now adding tracing headers rather than removing them, e.g., 'Failed to add tracing headers'.
this.log.debug('Failed to remove tracing header', 'url', url, 'referer', referer, 'error', error.message);

AgnesToulet and others added 2 commits May 13, 2025 17:44
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Ezequiel Victorero <ezequiel.victorero@grafana.com>
@AgnesToulet AgnesToulet merged commit 7d7f79b into master May 13, 2025
9 checks passed
@AgnesToulet AgnesToulet deleted the tracing/fix-headers branch May 13, 2025 15:55
@evictorero evictorero mentioned this pull request May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants