add source param in CDP messages
This commit is contained in:
@@ -600,6 +600,12 @@ async function handleCommand(msg: ExtensionCommandMessage): Promise<any> {
|
|||||||
|
|
||||||
const debuggee = targetTabId ? { tabId: targetTabId } : undefined
|
const debuggee = targetTabId ? { tabId: targetTabId } : undefined
|
||||||
|
|
||||||
|
// TODO disable network things?
|
||||||
|
// if (msg.params.method === 'Network.enable' && msg.params.source !== 'playwriter') {
|
||||||
|
// logger.debug('Skipping Network.enable from non-playwriter CDP client:', msg.params.sessionId)
|
||||||
|
// return {}
|
||||||
|
// }
|
||||||
|
|
||||||
switch (msg.params.method) {
|
switch (msg.params.method) {
|
||||||
case 'Runtime.enable': {
|
case 'Runtime.enable': {
|
||||||
if (!debuggee) {
|
if (!debuggee) {
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ export async function startPlayWriterCDPRelayServer({ port = 19988, host = '127.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function routeCdpCommand({ method, params, sessionId }: { method: string; params: any; sessionId?: string }) {
|
async function routeCdpCommand({ method, params, sessionId, source }: { method: string; params: any; sessionId?: string; source?: 'playwriter' }) {
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case 'Browser.getVersion': {
|
case 'Browser.getVersion': {
|
||||||
return {
|
return {
|
||||||
@@ -349,14 +349,14 @@ export async function startPlayWriterCDPRelayServer({ port = 19988, host = '127.
|
|||||||
case 'Target.createTarget': {
|
case 'Target.createTarget': {
|
||||||
return await sendToExtension({
|
return await sendToExtension({
|
||||||
method: 'forwardCDPCommand',
|
method: 'forwardCDPCommand',
|
||||||
params: { method, params }
|
params: { method, params, source }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'Target.closeTarget': {
|
case 'Target.closeTarget': {
|
||||||
return await sendToExtension({
|
return await sendToExtension({
|
||||||
method: 'forwardCDPCommand',
|
method: 'forwardCDPCommand',
|
||||||
params: { method, params }
|
params: { method, params, source }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,7 +386,7 @@ export async function startPlayWriterCDPRelayServer({ port = 19988, host = '127.
|
|||||||
|
|
||||||
const result = await sendToExtension({
|
const result = await sendToExtension({
|
||||||
method: 'forwardCDPCommand',
|
method: 'forwardCDPCommand',
|
||||||
params: { sessionId, method, params }
|
params: { sessionId, method, params, source }
|
||||||
})
|
})
|
||||||
|
|
||||||
await contextCreatedPromise
|
await contextCreatedPromise
|
||||||
@@ -397,7 +397,7 @@ export async function startPlayWriterCDPRelayServer({ port = 19988, host = '127.
|
|||||||
|
|
||||||
return await sendToExtension({
|
return await sendToExtension({
|
||||||
method: 'forwardCDPCommand',
|
method: 'forwardCDPCommand',
|
||||||
params: { sessionId, method, params }
|
params: { sessionId, method, params, source }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -582,7 +582,7 @@ export async function startPlayWriterCDPRelayServer({ port = 19988, host = '127.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const { id, sessionId, method, params } = message
|
const { id, sessionId, method, params, source } = message
|
||||||
|
|
||||||
logCdpMessage({
|
logCdpMessage({
|
||||||
direction: 'from-playwright',
|
direction: 'from-playwright',
|
||||||
@@ -607,7 +607,7 @@ export async function startPlayWriterCDPRelayServer({ port = 19988, host = '127.
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result: any = await routeCdpCommand({ method, params, sessionId })
|
const result: any = await routeCdpCommand({ method, params, sessionId, source })
|
||||||
|
|
||||||
if (method === 'Target.setAutoAttach' && !sessionId) {
|
if (method === 'Target.setAutoAttach' && !sessionId) {
|
||||||
for (const target of connectedTargets.values()) {
|
for (const target of connectedTargets.values()) {
|
||||||
|
|||||||
@@ -73,7 +73,13 @@ export class CDPSession implements ICDPSession {
|
|||||||
params?: ProtocolMapping.Commands[K]['paramsType'][0],
|
params?: ProtocolMapping.Commands[K]['paramsType'][0],
|
||||||
): Promise<ProtocolMapping.Commands[K]['returnType']> {
|
): Promise<ProtocolMapping.Commands[K]['returnType']> {
|
||||||
const id = ++this.messageId
|
const id = ++this.messageId
|
||||||
const message: Record<string, unknown> = { id, method, params }
|
const message: {
|
||||||
|
id: number
|
||||||
|
method: K
|
||||||
|
params?: ProtocolMapping.Commands[K]['paramsType'][0]
|
||||||
|
sessionId?: string
|
||||||
|
source?: 'playwriter'
|
||||||
|
} = { id, method, params, source: 'playwriter' }
|
||||||
if (this.sessionId) {
|
if (this.sessionId) {
|
||||||
message.sessionId = this.sessionId
|
message.sessionId = this.sessionId
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import type { Protocol } from 'devtools-protocol';
|
import type { Protocol } from 'devtools-protocol';
|
||||||
import type { ProtocolMapping } from 'devtools-protocol/types/protocol-mapping.js';
|
import type { ProtocolMapping } from 'devtools-protocol/types/protocol-mapping.js';
|
||||||
|
|
||||||
|
export type CDPCommandSource = 'playwriter';
|
||||||
|
|
||||||
export type CDPCommandFor<T extends keyof ProtocolMapping.Commands> = {
|
export type CDPCommandFor<T extends keyof ProtocolMapping.Commands> = {
|
||||||
id: number;
|
id: number;
|
||||||
sessionId?: string;
|
sessionId?: string;
|
||||||
method: T;
|
method: T;
|
||||||
params?: ProtocolMapping.Commands[T]['paramsType'][0];
|
params?: ProtocolMapping.Commands[T]['paramsType'][0];
|
||||||
|
source?: CDPCommandSource;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CDPCommand = {
|
export type CDPCommand = {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ type ForwardCDPCommand =
|
|||||||
method: K
|
method: K
|
||||||
sessionId?: string
|
sessionId?: string
|
||||||
params?: ProtocolMapping.Commands[K]['paramsType'][0]
|
params?: ProtocolMapping.Commands[K]['paramsType'][0]
|
||||||
|
source?: 'playwriter'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}[keyof ProtocolMapping.Commands]
|
}[keyof ProtocolMapping.Commands]
|
||||||
|
|||||||
Reference in New Issue
Block a user