MCPcopy
hub / github.com/vercel/next.js / Playwright

Class Playwright

test/lib/browsers/playwright.ts:85–731  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83 | 'commit'
84
85export class Playwright<TCurrent = undefined> {
86 private activeTrace?: string
87 private eventCallbacks: Record<EventType, Set<(...args: any[]) => void>> = {
88 request: new Set(),
89 response: new Set(),
90 }
91 private async initContextTracing(url: string, context: BrowserContext) {
92 if (!tracePlaywright) {
93 return
94 }
95
96 try {
97 // Clean up if any previous traces are still active
98 await teardown(this.teardownTracing.bind(this))
99
100 await context.tracing.start({
101 screenshots: true,
102 snapshots: true,
103 sources: true,
104 })
105 this.activeTrace = encodeURIComponent(url)
106 } catch (e) {
107 this.activeTrace = undefined
108 }
109 }
110
111 private async teardownTracing() {
112 if (!this.activeTrace) {
113 return
114 }
115
116 try {
117 const traceDir = path.join(__dirname, '../../traces')
118 const traceOutputPath = path.join(
119 traceDir,
120 `${path
121 .relative(path.join(__dirname, '../../'), process.env.TEST_FILE_PATH!)
122 .replace(/\//g, '-')}`,
123 `playwright-${this.activeTrace}-${Date.now()}.zip`
124 )
125
126 await fs.remove(traceOutputPath)
127 await context!.tracing.stop({
128 path: traceOutputPath,
129 })
130 } catch (e) {
131 require('console').warn('Failed to teardown playwright tracing', e)
132 } finally {
133 this.activeTrace = undefined
134 }
135 }
136
137 on(
138 event: 'request',
139 cb: (request: PlaywrightRequest) => void | Promise<void>
140 ): void
141 on(
142 event: 'response',

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected