Skip to content

Commit 9f32ebf

Browse files
committed
address comments
1 parent d5d5276 commit 9f32ebf

4 files changed

Lines changed: 18 additions & 42 deletions

File tree

go/modcdp/injector/extension.zip

-201 Bytes
Binary file not shown.

js/src/client/ModCDPClient.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,19 +1042,6 @@ export class ModCDPClient extends ModCDPEventEmitter {
10421042
if (this.server?.server_close_browser_on_downstream_disconnect !== true) return;
10431043
const interval_ms = this.client.client_heartbeat_interval_ms;
10441044
this.heartbeat_timer = setInterval(() => {
1045-
if (this.ext_session_id) {
1046-
void this._sendRaw(
1047-
wrapCommandIfNeeded(
1048-
"Mod.ping",
1049-
{ sent_at: Date.now() },
1050-
{
1051-
routes: this.client.client_routes,
1052-
cdpSessionId: this.ext_session_id,
1053-
},
1054-
),
1055-
).catch(() => {});
1056-
return;
1057-
}
10581045
void this.send("Mod.ping", { sent_at: Date.now() }).catch(() => {});
10591046
}, interval_ms);
10601047
}

js/src/server/ModCDPServer.ts

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -90,53 +90,42 @@ export function installModCDPServer(globalScope: ModCDPGlobalScope = globalThis
9090
};
9191
const attachedDebuggees = new Set<string>();
9292
let runtime_types_promise: Promise<unknown> | null = null;
93-
const DOWNSTREAM_CLIENT_KEY = "downstream_client";
94-
const registered_downstream_client_keys = new Set<string>();
95-
const downstream_client_leases = new Map<
96-
string,
97-
{
98-
cdpSessionId: string | null;
99-
last_seen_at: number;
100-
timer: ReturnType<typeof setTimeout>;
101-
}
102-
>();
103-
104-
function downstreamClientKey(_cdpSessionId: string | null) {
105-
return DOWNSTREAM_CLIENT_KEY;
93+
let downstream_client_registered = false;
94+
let downstream_client_lease: {
95+
cdpSessionId: string | null;
96+
last_seen_at: number;
97+
timer: ReturnType<typeof setTimeout>;
98+
} | null = null;
99+
100+
function registerDownstreamClient() {
101+
downstream_client_registered = true;
106102
}
107103

108-
function registerDownstreamClient(cdpSessionId: string | null) {
109-
const client_key = downstreamClientKey(cdpSessionId);
110-
registered_downstream_client_keys.add(client_key);
111-
return client_key;
112-
}
113-
114-
function clearDownstreamClientLease(client_key: string) {
115-
const lease = downstream_client_leases.get(client_key);
104+
function clearDownstreamClientLease() {
105+
const lease = downstream_client_lease;
116106
if (!lease) return null;
117107
clearTimeout(lease.timer);
118-
downstream_client_leases.delete(client_key);
108+
downstream_client_lease = null;
119109
return lease;
120110
}
121111

122112
function touchDownstreamClientLease(cdpSessionId: string | null) {
123113
const timeout_ms = ModCDPServer.downstream_client_timeout_ms;
124114
if (!(timeout_ms > 0)) return;
125-
const client_key = downstreamClientKey(cdpSessionId);
126-
if (!registered_downstream_client_keys.has(client_key)) return;
115+
if (!downstream_client_registered) return;
127116
const last_seen_at = Date.now();
128-
clearDownstreamClientLease(client_key);
117+
clearDownstreamClientLease();
129118
const timer = setTimeout(() => {
130-
const expired = clearDownstreamClientLease(client_key);
119+
const expired = clearDownstreamClientLease();
131120
if (!expired) return;
132121
if (ModCDPServer.close_browser_on_downstream_disconnect !== true) return;
133122
void ModCDPServer.sendLoopback("Browser.close", {}, null).catch(() => {});
134123
}, timeout_ms);
135-
downstream_client_leases.set(client_key, {
124+
downstream_client_lease = {
136125
cdpSessionId,
137126
last_seen_at,
138127
timer,
139-
});
128+
};
140129
}
141130

142131
function nativeCommandSchema(method: string) {
@@ -1272,7 +1261,7 @@ export function installModCDPServer(globalScope: ModCDPGlobalScope = globalThis
12721261
},
12731262

12741263
async handleCommand(method: string, params: ProtocolParams = {}, cdpSessionId: string | null = null) {
1275-
if (method === "Mod.configure") registerDownstreamClient(cdpSessionId);
1264+
if (method === "Mod.configure") registerDownstreamClient();
12761265
touchDownstreamClientLease(cdpSessionId);
12771266
const request = { method, params, cdpSessionId };
12781267
const middlewareParams = await this.runMiddleware("request", method, params, { cdpSessionId, request });

python/modcdp/extension.zip

-201 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)