MCPcopy
hub / github.com/microsoft/playwright / DashboardClient

Class DashboardClient

packages/dashboard/src/dashboardClient.ts:27–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25};
26
27export class DashboardClient {
28 private _transport: Transport;
29 private _listeners = new Map<string, Set<Function>>();
30
31 onopen?: () => void;
32 onclose?: (reason?: string) => void;
33
34 private constructor(transport: Transport) {
35 this._transport = transport;
36 this._transport.onopen = () => {
37 this.onopen?.();
38 };
39 this._transport.onevent = (method: string, params: any) => {
40 this._fireEvent(method, params);
41 };
42 this._transport.onclose = (reason?: string) => {
43 this.onclose?.(reason);
44 };
45 }
46
47 static create(url: string): DashboardClientChannel {
48 const transport = new Transport(url);
49 const client = new DashboardClient(transport);
50 return new Proxy(client, {
51 get(target: DashboardClient, prop: string | symbol, receiver: any): any {
52 if (typeof prop === 'symbol' || prop in target)
53 return Reflect.get(target, prop, receiver);
54 // Prevent the proxy from being treated as a thenable.
55 if (prop === 'then')
56 return undefined;
57 return (params?: any) => target._transport.send(prop, params);
58 }
59 }) as unknown as DashboardClientChannel;
60 }
61
62 private _fireEvent(event: string, params: any) {
63 const set = this._listeners.get(event);
64 if (set) {
65 for (const listener of set)
66 listener(params);
67 }
68 }
69
70 on(event: string, listener: Function): void {
71 let set = this._listeners.get(event);
72 if (!set) {
73 set = new Set();
74 this._listeners.set(event, set);
75 }
76 set.add(listener);
77 }
78
79 off(event: string, listener: Function): void {
80 this._listeners.get(event)?.delete(listener);
81 }
82
83 close() {
84 this._transport.close();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…