Skip to content

Commit

Permalink
fix: hide cdp.send after the mapper receives it (#3137)
Browse files Browse the repository at this point in the history
Currently, the CDP connection is exposed on the global object. With this
change, the CDP connection's send method would be only internally
available.
  • Loading branch information
OrKoN authored Feb 21, 2025
1 parent 0a23d1b commit 9ad3d11
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/bidiTab/Transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,12 @@ export class WindowBidiTransport implements BidiTransport {

export class WindowCdpTransport implements Transport {
#onMessage: ((message: string) => void) | null = null;
#cdpSend: typeof window.cdp.send;

constructor() {
this.#cdpSend = window.cdp.send;
// @ts-expect-error removing cdp
window.cdp.send = undefined;
window.cdp.onmessage = (message: string) => {
this.#onMessage?.call(null, message);
};
Expand All @@ -200,7 +204,7 @@ export class WindowCdpTransport implements Transport {
}

sendMessage(message: string) {
window.cdp.send(message);
this.#cdpSend(message);
}

close() {
Expand Down

0 comments on commit 9ad3d11

Please sign in to comment.