@steambrew/client
Version:
A support library for creating plugins with Millennium.
82 lines (81 loc) • 3.9 kB
TypeScript
import ProtocolMapping from 'devtools-protocol/types/protocol-mapping';
/** Returnable IPC types */
type IPCType = string | number | boolean | void;
type Millennium = {
/**
* Call a method on the backend
* @deprecated Use `callable` instead.
* Example usage:
* ```typescript
* // before
* const result = await Millennium.callServerMethod('methodName', { arg1: 'value' });
* // after
* const method = callable<[{ arg1: string }]>("methodName");
*
* const result1 = await method({ arg1: 'value1' });
* const result2 = await method({ arg1: 'value2' });
* ```
*/
callServerMethod: (methodName: string, kwargs?: object) => Promise<any>;
findElement: (privateDocument: Document, querySelector: string, timeOut?: number) => Promise<NodeListOf<Element>>;
exposeObj?: <T extends object>(obj: T) => any;
AddWindowCreateHook?: (callback: (context: object) => void) => void;
};
/**
* Make reusable IPC call declarations
*
* frontend:
* ```typescript
* const method = callable<[{ arg1: string }]>("methodName"); // declare the method
* method({ arg1: 'value' }); // call the method
* ```
*
* backend:
* ```python
* def methodName(arg1: str):
* pass
* ```
*/
declare const callable: <Params extends [params: Record<string, IPCType>] | [] = [], Return extends IPCType = IPCType>(route: string) => (...params: Params) => Promise<Return>;
export declare const pluginSelf: any;
declare const CDP_PROXY_BINDING = "__millennium_cdp_proxy__";
declare const CDP_EXTENSION_BINDING = "__millennium_extension_route__";
declare const CDP_EXT_RESP = "MILLENNIUM_CHROME_DEV_TOOLS_PROTOCOL_DO_NOT_USE_OR_OVERRIDE_ONMESSAGE";
declare global {
interface Window {
Millennium: Millennium;
[CDP_EXT_RESP]: {
__handleCDPResponse: (response: any) => void;
};
[CDP_EXTENSION_BINDING]: (message: string) => void;
[CDP_PROXY_BINDING]: (message: string) => void;
__millennium_cdp_resolve__: (callbackId: number, result: any) => void;
__millennium_cdp_reject__: (callbackId: number, error: string) => void;
__millennium_cdp_event__: (data: any) => void;
}
}
declare const BindPluginSettings: () => any;
declare const pluginConfig: {
get: <T = any>(key: string) => Promise<T>;
set: (key: string, value: any) => Promise<void>;
delete: (key: string) => Promise<void>;
getAll: <T = Record<string, any>>() => Promise<T>;
};
declare const usePluginConfig: {
<T = any>(key: string): [T | undefined, (value: T) => Promise<void>];
(): [Record<string, any>, (key: string, value: any) => Promise<void>];
};
declare const subscribePluginConfig: (cb: (key: string, value: any) => void) => () => void;
export declare class MillenniumChromeDevToolsProtocol {
protected readonly _pluginName: string;
eventListeners: Map<string, Set<(params: any) => void>>;
private readonly _eventDispatcher;
constructor(pluginName: string);
on<T extends keyof ProtocolMapping.Events>(event: T, listener: (params: ProtocolMapping.Events[T][0]) => void): () => void;
off<T extends keyof ProtocolMapping.Events>(event: T, listener: (params: ProtocolMapping.Events[T][0]) => void): void;
send<T extends keyof ProtocolMapping.Commands>(method: T, params?: ProtocolMapping.Commands[T]['paramsType'][0], sessionId?: string): Promise<ProtocolMapping.Commands[T]['returnType']>;
protected _sendViaExtensionRoute<T extends keyof ProtocolMapping.Commands>(method: T, params: ProtocolMapping.Commands[T]['paramsType'][0], sessionId?: string): Promise<ProtocolMapping.Commands[T]['returnType']>;
}
declare const ChromeDevToolsProtocol: MillenniumChromeDevToolsProtocol;
declare const Millennium: Millennium;
export { BindPluginSettings, callable, ChromeDevToolsProtocol, Millennium, pluginConfig, subscribePluginConfig, usePluginConfig };