-
Notifications
You must be signed in to change notification settings - Fork 6.2k
feat(trace): split API requests into a separate network stream #42073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,7 @@ export interface HarTracerDelegate { | |
|
|
||
| type HarTracerOptions = { | ||
| content: 'omit' | 'attach' | 'embed'; | ||
| includeAPIRequests?: boolean; | ||
| includeTraceInfo: boolean; | ||
| recordRequestOverrides: boolean; | ||
| waitForContentOnStop: boolean; | ||
|
|
@@ -105,11 +106,14 @@ export class HarTracer { | |
| return; | ||
| this._options.omitScripts = options.omitScripts; | ||
| this._started = true; | ||
| const apiRequest = this._context instanceof APIRequestContext ? this._context : this._context.fetchRequest; | ||
| this._eventListeners = [ | ||
| eventsHelper.addEventListener(apiRequest, APIRequestContext.Events.Request, (event: APIRequestEvent) => this._onAPIRequest(event)), | ||
| eventsHelper.addEventListener(apiRequest, APIRequestContext.Events.RequestFinished, (event: APIRequestFinishedEvent) => this._onAPIRequestFinished(event)), | ||
| ]; | ||
| this._eventListeners = []; | ||
| if (this._options.includeAPIRequests !== false) { | ||
| const apiRequest = this._context instanceof APIRequestContext ? this._context : this._context.fetchRequest; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also unclear why we would switch to fetch context in this case.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note that this check existed before this PR a standalone |
||
| this._eventListeners.push( | ||
| eventsHelper.addEventListener(apiRequest, APIRequestContext.Events.Request, (event: APIRequestEvent) => this._onAPIRequest(event)), | ||
| eventsHelper.addEventListener(apiRequest, APIRequestContext.Events.RequestFinished, (event: APIRequestFinishedEvent) => this._onAPIRequestFinished(event)), | ||
| ); | ||
| } | ||
| if (this._context instanceof BrowserContext) { | ||
| this._eventListeners.push( | ||
| eventsHelper.addEventListener(this._context, BrowserContext.Events.Page, (page: Page) => this._createPageEntryIfNeeded(page)), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand the logic that "enables" api requests when api request context is passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is to handle things like
playwright.request.newContext().tracing.startHar()vs a "regular"BrowserContext(i.e. the latter will not include API requests in the HAR whereas the former will only include API requests in the HAR)