|
| 1 | +import { CDPConnection } from "../connection"; |
| 2 | +import { CDPEventEmitter } from "../emitter"; |
| 3 | +import type { |
| 4 | + CDPDebuggerCallFrame, |
| 5 | + CDPDebuggerPausedReason, |
| 6 | + CDPExecutionContextId, |
| 7 | + CDPRuntimeScriptId, |
| 8 | + CDPRuntimeStackTrace, |
| 9 | + CDPSessionId, |
| 10 | +} from "../types"; |
| 11 | + |
| 12 | +interface ScriptData { |
| 13 | + scriptId: CDPRuntimeScriptId; |
| 14 | + /** URL or name of the script parsed (if any). */ |
| 15 | + url: string; |
| 16 | + /** Line offset of the script within the resource with given URL (for script tags). */ |
| 17 | + startLine: number; |
| 18 | + /** Column offset of the script within the resource with given URL. */ |
| 19 | + startColumn: number; |
| 20 | + /** Last line of the script. */ |
| 21 | + endLine: number; |
| 22 | + /** Length of the last line of the script. */ |
| 23 | + endColumn: number; |
| 24 | + executionContextId: CDPExecutionContextId; |
| 25 | + /** Content hash of the script, SHA-256. */ |
| 26 | + hash: string; |
| 27 | + /** For Wasm modules, the content of the build_id custom section. For JavaScript the debugId magic comment. */ |
| 28 | + buildId: string; |
| 29 | + /** Embedder-specific auxiliary data likely matching {isDefault: boolean, type: 'default'|'isolated'|'worker', frameId: string} */ |
| 30 | + executionContextAuxData?: Record<string, unknown>; |
| 31 | + sourceMapURL?: string; |
| 32 | + /** True, if this script has sourceURL. */ |
| 33 | + hasSourceURL?: boolean; |
| 34 | + /** True, if this script is ES6 module. */ |
| 35 | + isModule?: boolean; |
| 36 | + /** This script length. */ |
| 37 | + length?: number; |
| 38 | +} |
| 39 | + |
| 40 | +interface GetScriptSourceResponse { |
| 41 | + /** Script source (empty in case of Wasm bytecode). */ |
| 42 | + scriptSource: string; |
| 43 | + /** Wasm bytecode. (Encoded as a base64 string when passed over JSON) */ |
| 44 | + bytecode?: string; |
| 45 | +} |
| 46 | + |
| 47 | +export interface DebuggerEvents { |
| 48 | + paused: { |
| 49 | + callFrames: CDPDebuggerCallFrame; |
| 50 | + /** Location of console.profileEnd(). */ |
| 51 | + reason: CDPDebuggerPausedReason; |
| 52 | + /** Object containing break-specific auxiliary properties. */ |
| 53 | + data?: Record<string, unknown>; |
| 54 | + asyncStackTrace?: CDPRuntimeStackTrace; |
| 55 | + }; |
| 56 | + resumed: Record<never, unknown>; |
| 57 | + scriptFailedToParse: ScriptData; |
| 58 | + scriptParsed: ScriptData; |
| 59 | +} |
| 60 | + |
| 61 | +/** @link https://chromedevtools.github.io/devtools-protocol/1-3/Debugger/ */ |
| 62 | +export class CDPDebugger extends CDPEventEmitter<DebuggerEvents> { |
| 63 | + private readonly _connection: CDPConnection; |
| 64 | + |
| 65 | + public constructor(connection: CDPConnection) { |
| 66 | + super(); |
| 67 | + |
| 68 | + this._connection = connection; |
| 69 | + } |
| 70 | + |
| 71 | + /** @param sessionId result of "Target.attachToTarget" */ |
| 72 | + /** @link https://chromedevtools.github.io/devtools-protocol/1-3/Debugger/#method-disable */ |
| 73 | + async disable(sessionId: CDPSessionId): Promise<void> { |
| 74 | + return this._connection.request("Debugger.disable", { sessionId }); |
| 75 | + } |
| 76 | + |
| 77 | + /** @param sessionId result of "Target.attachToTarget" */ |
| 78 | + /** @link https://chromedevtools.github.io/devtools-protocol/1-3/Debugger/#method-enable */ |
| 79 | + async enable(sessionId: CDPSessionId): Promise<void> { |
| 80 | + return this._connection.request("Debugger.enable", { sessionId }); |
| 81 | + } |
| 82 | + |
| 83 | + /** @link https://chromedevtools.github.io/devtools-protocol/1-3/Debugger/#method-resume */ |
| 84 | + async resume(sessionId: CDPSessionId, terminateOnResume?: boolean): Promise<void> { |
| 85 | + return this._connection.request("Debugger.resume", { sessionId, params: { terminateOnResume } }); |
| 86 | + } |
| 87 | + |
| 88 | + /** @link https://chromedevtools.github.io/devtools-protocol/1-3/Debugger/#method-getScriptSource */ |
| 89 | + async getScriptSource(sessionId: CDPSessionId, scriptId: CDPRuntimeScriptId): Promise<GetScriptSourceResponse> { |
| 90 | + return this._connection.request("Debugger.getScriptSource", { sessionId, params: { scriptId }}); |
| 91 | + } |
| 92 | +} |
0 commit comments