fix(tracing): support old traces with consoleMessage.args (#27095)

Fixes #27072.
This commit is contained in:
Dmitry Gozman 2023-09-14 17:07:29 -07:00 committed by GitHub
parent b3edf8e562
commit a26f568b36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -384,7 +384,9 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snaps
onEvent(sdkObject: SdkObject, event: trace.EventTraceEvent) {
if (!sdkObject.attribution.context)
return;
if (event.method === 'console' || (event.method === '__create__' && event.class === 'ConsoleMessage')) {
if (event.method === 'console' ||
(event.method === '__create__' && event.class === 'ConsoleMessage') ||
(event.method === '__create__' && event.class === 'JSHandle')) {
// Console messages are handled separately.
return;
}

View File

@ -38,6 +38,7 @@ export class TraceModel {
private _backend!: TraceModelBackend;
private _attachments = new Map<string, trace.AfterActionTraceEventAttachment>();
private _resourceToContentType = new Map<string, string>();
private _jsHandles = new Map<string, { preview: string }>();
constructor() {
}
@ -112,6 +113,7 @@ export class TraceModel {
}
this._snapshotStorage!.finalize();
this._jsHandles.clear();
}
async hasEntry(filename: string): Promise<boolean> {
@ -297,12 +299,23 @@ export class TraceModel {
return null;
if (event.type === 'event') {
if (metadata.method === '__create__' && metadata.type === 'JSHandle')
this._jsHandles.set(metadata.params.guid, metadata.params.initializer);
if (metadata.method === '__create__' && metadata.type === 'ConsoleMessage') {
return {
type: 'object',
class: metadata.type,
guid: metadata.params.guid,
initializer: metadata.params.initializer,
initializer: {
...metadata.params.initializer,
args: metadata.params.initializer.args?.map((arg: any) => {
if (arg.guid) {
const handle = this._jsHandles.get(arg.guid);
return { preview: handle?.preview || '', value: '' };
}
return { preview: '', value: '' };
})
},
};
}
return {