browser-debugger-cli
Version:
DevTools telemetry in your terminal. For humans and agents. Direct WebSocket to Chrome's debugging port.
118 lines • 2.46 kB
JavaScript
/**
* cdpMessages - Sample CDP protocol messages for tests
*
* Provides realistic CDP message fixtures to keep tests concise and readable.
*/
/**
* Sample CDP request message
*/
export const CDP_REQUEST = {
id: 1,
method: 'Target.getTargets',
params: {},
};
/**
* Sample CDP response message (success)
*/
export const CDP_RESPONSE_SUCCESS = {
id: 1,
result: {
targetInfos: [
{
targetId: 't1',
type: 'page',
title: 'Test Page',
url: 'http://localhost:3000',
attached: false,
canAccessOpener: false,
},
],
},
};
/**
* Sample CDP error response
*/
export const CDP_RESPONSE_ERROR = {
id: 1,
error: {
code: -32601,
message: 'Method not found',
},
};
/**
* Sample CDP event notification (no id)
*/
export const CDP_EVENT_NOTIFICATION = {
method: 'Target.targetCreated',
params: {
targetInfo: {
targetId: 't2',
type: 'page',
title: 'New Page',
url: 'http://localhost:4000',
attached: false,
canAccessOpener: false,
},
},
};
/**
* Sample CDP event with session ID
*/
export const CDP_EVENT_WITH_SESSION = {
method: 'Page.frameNavigated',
params: {
frame: {
id: 'frame-1',
loaderId: 'loader-1',
url: 'http://localhost:3000/page',
securityOrigin: 'http://localhost:3000',
mimeType: 'text/html',
},
},
sessionId: 'session-abc123',
};
/**
* Factory: Create a request message with custom ID
*/
export function createRequest(id, method, params) {
return {
id,
method,
params: params ?? {},
};
}
/**
* Factory: Create a success response
*/
export function createResponse(id, result) {
return {
id,
result,
};
}
/**
* Factory: Create an error response
*/
export function createErrorResponse(id, message, code = -32603) {
return {
id,
error: {
code,
message,
},
};
}
/**
* Factory: Create an event notification
*/
export function createEvent(method, params, sessionId) {
const event = {
method,
params: params ?? {},
};
if (sessionId) {
event.sessionId = sessionId;
}
return event;
}
//# sourceMappingURL=cdpMessages.js.map