cherry-pick(#27095): fix(tracing): support old traces with consoleMessage.args (#27124)

Fixes #27072.
This commit is contained in:
Dmitry Gozman 2023-09-15 10:31:33 -07:00 committed by GitHub
parent ed919f3dda
commit 2a577a5caf
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) { onEvent(sdkObject: SdkObject, event: trace.EventTraceEvent) {
if (!sdkObject.attribution.context) if (!sdkObject.attribution.context)
return; 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. // Console messages are handled separately.
return; return;
} }

View file

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