| 34 | import type * as actions from '@recorder/actions'; |
| 35 | |
| 36 | export class DebugController extends SdkObject { |
| 37 | static Events = { |
| 38 | StateChanged: 'stateChanged', |
| 39 | InspectRequested: 'inspectRequested', |
| 40 | SourceChanged: 'sourceChanged', |
| 41 | Paused: 'paused', |
| 42 | SetModeRequested: 'setModeRequested', |
| 43 | }; |
| 44 | |
| 45 | private _trackHierarchyListener: InstrumentationListener | undefined; |
| 46 | private _playwright: Playwright; |
| 47 | _sdkLanguage: Language = 'javascript'; |
| 48 | _generateAutoExpect = false; |
| 49 | |
| 50 | constructor(playwright: Playwright) { |
| 51 | super({ attribution: { isInternalPlaywright: true }, instrumentation: createInstrumentation() } as any, undefined, 'DebugController'); |
| 52 | this._playwright = playwright; |
| 53 | } |
| 54 | |
| 55 | initialize(progress: Progress, codegenId: string, sdkLanguage: Language) { |
| 56 | this._sdkLanguage = sdkLanguage; |
| 57 | } |
| 58 | |
| 59 | dispose() { |
| 60 | this._setReportStateChanged(false); |
| 61 | } |
| 62 | |
| 63 | setReportStateChanged(progress: Progress, enabled: boolean) { |
| 64 | this._setReportStateChanged(enabled); |
| 65 | } |
| 66 | |
| 67 | private _setReportStateChanged(enabled: boolean) { |
| 68 | if (enabled && !this._trackHierarchyListener) { |
| 69 | this._trackHierarchyListener = { |
| 70 | onPageOpen: () => this._emitSnapshot(false), |
| 71 | onPageClose: () => this._emitSnapshot(false), |
| 72 | }; |
| 73 | this._playwright.instrumentation.addListener(this._trackHierarchyListener, null); |
| 74 | this._emitSnapshot(true); |
| 75 | } else if (!enabled && this._trackHierarchyListener) { |
| 76 | this._playwright.instrumentation.removeListener(this._trackHierarchyListener); |
| 77 | this._trackHierarchyListener = undefined; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | async setRecorderMode(progress: Progress, params: { mode: Mode, testIdAttributeName?: string, generateAutoExpect?: boolean }) { |
| 82 | await this._closeBrowsersWithoutPages(progress); |
| 83 | this._generateAutoExpect = !!params.generateAutoExpect; |
| 84 | |
| 85 | if (params.mode === 'none') { |
| 86 | const promises = []; |
| 87 | for (const recorder of await progress.race(this._allRecorders())) { |
| 88 | promises.push(recorder.hideHighlightedSelector()); |
| 89 | promises.push(recorder.setMode('none')); |
| 90 | } |
| 91 | await progress.race(Promise.all(promises)); |
| 92 | return; |
| 93 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…