ipc: add .on
This commit is contained in:
parent
e1bb814c88
commit
bb4cd7195c
14
gluon.d.ts
vendored
14
gluon.d.ts
vendored
@ -179,7 +179,19 @@ type CDPApi = {
|
||||
* @default true
|
||||
*/
|
||||
useSessionId?: boolean
|
||||
): Promise<any>
|
||||
): Promise<any>,
|
||||
|
||||
/**
|
||||
* Hook into a specific CDP method being called.
|
||||
* @returns Function to unhook/unsubscribe.
|
||||
*/
|
||||
on(
|
||||
/** Method of CDP command to hook into. */
|
||||
method: string,
|
||||
|
||||
/** Callback to run when the given method is emitted. */
|
||||
callback: (message: any) => void
|
||||
): (() => void)
|
||||
};
|
||||
|
||||
type IdleAutoOptions = {
|
||||
|
@ -109,7 +109,17 @@ export default async (CDP, proc, injectionType = 'browser', { dataPath, browserN
|
||||
ipc: IPC,
|
||||
|
||||
cdp: {
|
||||
send: (method, params, useSessionId = true) => CDP.sendMessage(method, params, useSessionId ? sessionId : undefined)
|
||||
send: (method, params, useSessionId = true) => CDP.sendMessage(method, params, useSessionId ? sessionId : undefined),
|
||||
on: (method, handler, once = false) => {
|
||||
const unhook = CDP.onMessage(msg => {
|
||||
if (msg.method === method) {
|
||||
handler(msg);
|
||||
if (once) unhook();
|
||||
}
|
||||
});
|
||||
|
||||
return unhook;
|
||||
}
|
||||
},
|
||||
|
||||
close: () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user