use cdp types safety
This commit is contained in:
@@ -1,20 +1,26 @@
|
|||||||
|
import { CDPCommand, CDPEvent, ProtocolMapping } from '../cdp-types.js'
|
||||||
|
|
||||||
export const VERSION = 1
|
export const VERSION = 1
|
||||||
|
|
||||||
|
type ForwardCDPCommand =
|
||||||
|
{
|
||||||
|
[K in keyof ProtocolMapping.Commands]: {
|
||||||
|
id: number
|
||||||
|
method: 'forwardCDPCommand'
|
||||||
|
params: {
|
||||||
|
method: K
|
||||||
|
sessionId?: string
|
||||||
|
params?: ProtocolMapping.Commands[K]['paramsType'][0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}[keyof ProtocolMapping.Commands]
|
||||||
|
|
||||||
export type ExtensionCommandMessage =
|
export type ExtensionCommandMessage =
|
||||||
| {
|
| {
|
||||||
id: number
|
id: number
|
||||||
method: 'attachToTab'
|
method: 'attachToTab'
|
||||||
params?: object
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
id: number
|
|
||||||
method: 'forwardCDPCommand'
|
|
||||||
params: {
|
|
||||||
method: string
|
|
||||||
sessionId?: string
|
|
||||||
params?: any
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
| ForwardCDPCommand
|
||||||
|
|
||||||
export type ExtensionResponseMessage = {
|
export type ExtensionResponseMessage = {
|
||||||
id: number
|
id: number
|
||||||
@@ -22,13 +28,20 @@ export type ExtensionResponseMessage = {
|
|||||||
error?: string
|
error?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ExtensionEventMessage = {
|
/**
|
||||||
method: 'forwardCDPEvent'
|
* This produces a discriminated union for narrowing, similar to ForwardCDPCommand,
|
||||||
params: {
|
* but for forwarded CDP events. Uses CDPEvent to maintain proper type extraction.
|
||||||
method: string
|
*/
|
||||||
sessionId?: string
|
export type ExtensionEventMessage =
|
||||||
params?: any
|
{
|
||||||
}
|
[K in keyof ProtocolMapping.Events]: {
|
||||||
}
|
method: 'forwardCDPEvent'
|
||||||
|
params: {
|
||||||
|
method: CDPEvent<K>['method']
|
||||||
|
sessionId?: string
|
||||||
|
params?: CDPEvent<K>['params']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}[keyof ProtocolMapping.Events]
|
||||||
|
|
||||||
export type ExtensionMessage = ExtensionResponseMessage | ExtensionEventMessage
|
export type ExtensionMessage = ExtensionResponseMessage | ExtensionEventMessage
|
||||||
|
|||||||
Reference in New Issue
Block a user