|
| 1 | +/** |
| 2 | + * Copyright (c) Microsoft Corporation. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import type { Entry as ResourceSnapshot } from '@trace/har'; |
| 18 | + |
| 19 | +type Language = 'javascript' | 'python' | 'java' | 'csharp' | 'jsonl'; |
| 20 | +type Point = { x: number, y: number }; |
| 21 | +type Size = { width: number, height: number }; |
| 22 | + |
| 23 | +type StackFrame = { |
| 24 | + file: string, |
| 25 | + line: number, |
| 26 | + column: number, |
| 27 | + function?: string, |
| 28 | +}; |
| 29 | + |
| 30 | +type Binary = Buffer; |
| 31 | + |
| 32 | +type SerializedValue = { |
| 33 | + n?: number, |
| 34 | + b?: boolean, |
| 35 | + s?: string, |
| 36 | + v?: 'null' | 'undefined' | 'NaN' | 'Infinity' | '-Infinity' | '-0', |
| 37 | + d?: string, |
| 38 | + u?: string, |
| 39 | + bi?: string, |
| 40 | + ta?: { |
| 41 | + b: Binary, |
| 42 | + k: 'i8' | 'ui8' | 'ui8c' | 'i16' | 'ui16' | 'i32' | 'ui32' | 'f32' | 'f64' | 'bi64' | 'bui64', |
| 43 | + }, |
| 44 | + e?: { |
| 45 | + m: string, |
| 46 | + n: string, |
| 47 | + s: string, |
| 48 | + }, |
| 49 | + r?: { |
| 50 | + p: string, |
| 51 | + f: string, |
| 52 | + }, |
| 53 | + a?: SerializedValue[], |
| 54 | + o?: { |
| 55 | + k: string, |
| 56 | + v: SerializedValue, |
| 57 | + }[], |
| 58 | + h?: number, |
| 59 | + id?: number, |
| 60 | + ref?: number, |
| 61 | +}; |
| 62 | + |
| 63 | +type SerializedError = { |
| 64 | + error?: { |
| 65 | + message: string, |
| 66 | + name: string, |
| 67 | + stack?: string, |
| 68 | + }, |
| 69 | + value?: SerializedValue, |
| 70 | +}; |
| 71 | + |
| 72 | +// Text node. |
| 73 | +type TextNodeSnapshot = string; |
| 74 | +// Subtree reference, "x snapshots ago, node #y". Could point to a text node. |
| 75 | +// Only nodes that are not references are counted, starting from zero, using post-order traversal. |
| 76 | +type SubtreeReferenceSnapshot = [ [number, number] ]; |
| 77 | +// Node name, and optional attributes and child nodes. |
| 78 | +type NodeNameAttributesChildNodesSnapshot = [ string ] | [ string, Record<string, string>, ...NodeSnapshot[] ]; |
| 79 | + |
| 80 | +type NodeSnapshot = |
| 81 | + TextNodeSnapshot | |
| 82 | + SubtreeReferenceSnapshot | |
| 83 | + NodeNameAttributesChildNodesSnapshot; |
| 84 | + |
| 85 | +type ResourceOverride = { |
| 86 | + url: string, |
| 87 | + sha1?: string, |
| 88 | + ref?: number |
| 89 | +}; |
| 90 | + |
| 91 | +type FrameSnapshot = { |
| 92 | + snapshotName?: string, |
| 93 | + callId: string, |
| 94 | + pageId: string, |
| 95 | + frameId: string, |
| 96 | + frameUrl: string, |
| 97 | + timestamp: number, |
| 98 | + wallTime?: number, |
| 99 | + collectionTime: number, |
| 100 | + doctype?: string, |
| 101 | + html: NodeSnapshot, |
| 102 | + resourceOverrides: ResourceOverride[], |
| 103 | + viewport: { width: number, height: number }, |
| 104 | + isMainFrame: boolean, |
| 105 | +}; |
| 106 | + |
| 107 | +type BrowserContextEventOptions = { |
| 108 | + baseURL?: string, |
| 109 | + viewport?: Size, |
| 110 | + deviceScaleFactor?: number, |
| 111 | + isMobile?: boolean, |
| 112 | + userAgent?: string, |
| 113 | +}; |
| 114 | + |
| 115 | +export type ContextCreatedTraceEvent = { |
| 116 | + version: number, |
| 117 | + type: 'context-options', |
| 118 | + origin: 'testRunner' | 'library', |
| 119 | + browserName: string, |
| 120 | + channel?: string, |
| 121 | + platform: string, |
| 122 | + playwrightVersion?: string, |
| 123 | + wallTime: number, |
| 124 | + monotonicTime: number, |
| 125 | + title?: string, |
| 126 | + options: BrowserContextEventOptions, |
| 127 | + sdkLanguage?: Language, |
| 128 | + testIdAttributeName?: string, |
| 129 | + contextId?: string, |
| 130 | + testTimeout?: number, |
| 131 | + annotations?: TraceEventAnnotation[], |
| 132 | +}; |
| 133 | + |
| 134 | +export type ScreencastFrameTraceEvent = { |
| 135 | + type: 'screencast-frame', |
| 136 | + pageId: string, |
| 137 | + sha1: string, |
| 138 | + width: number, |
| 139 | + height: number, |
| 140 | + timestamp: number, |
| 141 | + frameSwapWallTime?: number, |
| 142 | +}; |
| 143 | + |
| 144 | +export type BeforeActionTraceEvent = { |
| 145 | + type: 'before', |
| 146 | + callId: string; |
| 147 | + startTime: number; |
| 148 | + title?: string; |
| 149 | + class: string; |
| 150 | + method: string; |
| 151 | + params: Record<string, any>; |
| 152 | + stepId?: string; |
| 153 | + beforeSnapshot?: string; |
| 154 | + stack?: StackFrame[]; |
| 155 | + pageId?: string; |
| 156 | + parentId?: string; |
| 157 | + group?: string; |
| 158 | +}; |
| 159 | + |
| 160 | +export type InputActionTraceEvent = { |
| 161 | + type: 'input', |
| 162 | + callId: string; |
| 163 | + inputSnapshot?: string; |
| 164 | + point?: Point; |
| 165 | +}; |
| 166 | + |
| 167 | +export type AfterActionTraceEventAttachment = { |
| 168 | + name: string; |
| 169 | + contentType: string; |
| 170 | + path?: string; |
| 171 | + sha1?: string; |
| 172 | + base64?: string; |
| 173 | +}; |
| 174 | + |
| 175 | +export type TraceEventAnnotation = { |
| 176 | + type: string, |
| 177 | + description?: string |
| 178 | +}; |
| 179 | + |
| 180 | +export type AfterActionTraceEvent = { |
| 181 | + type: 'after', |
| 182 | + callId: string; |
| 183 | + endTime: number; |
| 184 | + afterSnapshot?: string; |
| 185 | + error?: SerializedError['error']; |
| 186 | + attachments?: AfterActionTraceEventAttachment[]; |
| 187 | + annotations?: TraceEventAnnotation[]; |
| 188 | + result?: any; |
| 189 | + point?: Point; |
| 190 | +}; |
| 191 | + |
| 192 | +export type LogTraceEvent = { |
| 193 | + type: 'log', |
| 194 | + callId: string; |
| 195 | + time: number; |
| 196 | + message: string; |
| 197 | +}; |
| 198 | + |
| 199 | +export type EventTraceEvent = { |
| 200 | + type: 'event', |
| 201 | + time: number; |
| 202 | + class: string; |
| 203 | + method: string; |
| 204 | + params: any; |
| 205 | + pageId?: string; |
| 206 | +}; |
| 207 | + |
| 208 | +export type ConsoleMessageTraceEvent = { |
| 209 | + type: 'console'; |
| 210 | + time: number; |
| 211 | + pageId?: string; |
| 212 | + messageType: string, |
| 213 | + text: string, |
| 214 | + args?: { preview: string, value: any }[], |
| 215 | + location: { |
| 216 | + url: string, |
| 217 | + lineNumber: number, |
| 218 | + columnNumber: number, |
| 219 | + }, |
| 220 | +}; |
| 221 | + |
| 222 | +export type ResourceSnapshotTraceEvent = { |
| 223 | + type: 'resource-snapshot', |
| 224 | + snapshot: ResourceSnapshot, |
| 225 | +}; |
| 226 | + |
| 227 | +export type FrameSnapshotTraceEvent = { |
| 228 | + type: 'frame-snapshot', |
| 229 | + snapshot: FrameSnapshot, |
| 230 | +}; |
| 231 | + |
| 232 | +export type ActionTraceEvent = { |
| 233 | + type: 'action', |
| 234 | +} & Omit<BeforeActionTraceEvent, 'type'> |
| 235 | + & Omit<AfterActionTraceEvent, 'type'> |
| 236 | + & Omit<InputActionTraceEvent, 'type'>; |
| 237 | + |
| 238 | +export type StdioTraceEvent = { |
| 239 | + type: 'stdout' | 'stderr'; |
| 240 | + timestamp: number; |
| 241 | + text?: string; |
| 242 | + base64?: string; |
| 243 | +}; |
| 244 | + |
| 245 | +export type ErrorTraceEvent = { |
| 246 | + type: 'error'; |
| 247 | + message: string; |
| 248 | + stack?: StackFrame[]; |
| 249 | +}; |
| 250 | + |
| 251 | +export type TraceEvent = |
| 252 | + ContextCreatedTraceEvent | |
| 253 | + ScreencastFrameTraceEvent | |
| 254 | + ActionTraceEvent | |
| 255 | + BeforeActionTraceEvent | |
| 256 | + InputActionTraceEvent | |
| 257 | + AfterActionTraceEvent | |
| 258 | + EventTraceEvent | |
| 259 | + LogTraceEvent | |
| 260 | + ConsoleMessageTraceEvent | |
| 261 | + ResourceSnapshotTraceEvent | |
| 262 | + FrameSnapshotTraceEvent | |
| 263 | + StdioTraceEvent | |
| 264 | + ErrorTraceEvent; |
0 commit comments