Skip to content

Commit f5c6b7f

Browse files
committed
Release ModCDP 0.0.13
1 parent df6f777 commit f5c6b7f

18 files changed

Lines changed: 56 additions & 35 deletions

go/modcdp/client/ModCDPClient.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,14 +1385,14 @@ func handlerPointer(handler Handler) uintptr {
13851385
}
13861386

13871387
func (c *ModCDPClient) Close() {
1388-
if c.transport != nil {
1389-
_ = c.transport.Close()
1390-
c.transport = nil
1391-
}
13921388
if c.launchedBrowser != nil {
13931389
c.launchedBrowser.Close()
13941390
c.launchedBrowser = nil
13951391
}
1392+
if c.transport != nil {
1393+
_ = c.transport.Close()
1394+
c.transport = nil
1395+
}
13961396
for _, injector := range c.extensionInjectors {
13971397
_ = injector.Close()
13981398
}

go/modcdp/injector/ExtensionInjector_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func TestExtensionInjectorKeepsModCDPServiceWorkerAliveThroughOffscreenKeepalive
256256
t.Fatal(err)
257257
}
258258
versionResult, _ := version["result"].(map[string]any)
259-
if versionResult["value"] != float64(1) {
259+
if versionResult["value"] != float64(2) {
260260
t.Fatalf("ModCDP server version = %#v", versionResult["value"])
261261
}
262262
}

go/modcdp/translate/translate.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ func wrapServiceWorkerCommand(method string, params map[string]any, sessionID st
165165
}
166166
}
167167
runtimeParams := map[string]any{}
168+
unwrap := "runtime"
168169
switch method {
169170
case "Mod.evaluate":
170171
runtimeParams = wrapModCDPEvaluate(params, targetSessionID)
@@ -178,10 +179,7 @@ func wrapServiceWorkerCommand(method string, params map[string]any, sessionID st
178179
cdpSessionID = targetSessionID
179180
}
180181
runtimeParams = wrapCustomCommand(method, params, cdpSessionID)
181-
}
182-
unwrap := "runtime_json"
183-
if strings.HasPrefix(method, "Mod.") {
184-
unwrap = "runtime"
182+
unwrap = "runtime_json"
185183
}
186184
return []rawStep{{Method: "Runtime.callFunctionOn", Params: runtimeParams, Unwrap: unwrap}}
187185
}

go/modcdp/translate/translate_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ func TestTranslateRoutesWrapsAndUnwrapsModCDPProtocolMessagesDeterministically(t
4444
t.Fatalf("unwrap = %q", wrapped.Steps[0].Unwrap)
4545
}
4646

47+
configured, err := wrapCommandIfNeeded("Mod.configure", map[string]any{"server": map[string]any{"server_routes": map[string]any{"*.*": "loopback_cdp"}}}, DefaultClientRoutes(), "session-1")
48+
if err != nil {
49+
t.Fatal(err)
50+
}
51+
if configured.Steps[0].Unwrap != "runtime_json" {
52+
t.Fatalf("configure unwrap = %q", configured.Steps[0].Unwrap)
53+
}
54+
4755
unwrapped, err := unwrapResponseIfNeeded(map[string]any{"result": map[string]any{"type": "object", "value": map[string]any{"ok": true}}}, "runtime")
4856
if err != nil {
4957
t.Fatal(err)

js/src/client/ModCDPClient.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ import {
2929
type UpstreamTransport,
3030
} from "../transport/UpstreamTransport.js";
3131
import type { BrowserLauncher, BrowserLaunchOptions, LaunchedBrowser } from "../launcher/BrowserLauncher.js";
32-
import {
33-
type ExtensionInjectorConfig,
34-
type ExtensionInjector,
35-
type SendCDP,
36-
} from "../injector/ExtensionInjector.js";
32+
import { type ExtensionInjectorConfig, type ExtensionInjector, type SendCDP } from "../injector/ExtensionInjector.js";
3733
import { AutoSessionRouter } from "../router/AutoSessionRouter.js";
3834
import type {
3935
CdpCommandMessage,
@@ -811,9 +807,7 @@ export class ModCDPClient extends ModCDPEventEmitter {
811807
return new WebSocketUpstreamTransport();
812808
}
813809
case "pipe": {
814-
const { PipeUpstreamTransport } = await import(
815-
/* @vite-ignore */ "../transport/PipeUpstreamTransport.js"
816-
);
810+
const { PipeUpstreamTransport } = await import(/* @vite-ignore */ "../transport/PipeUpstreamTransport.js");
817811
return new PipeUpstreamTransport();
818812
}
819813
case "reversews": {
@@ -990,10 +984,10 @@ export class ModCDPClient extends ModCDPEventEmitter {
990984
async close() {
991985
for (const cleanup of this.event_wait_cleanups) cleanup();
992986
this.event_wait_cleanups.clear();
993-
await this.transport?.close();
994-
this.transport = null;
995987
if (this._launched) await this._launched.close();
996988
this._launched = null;
989+
await this.transport?.close();
990+
this.transport = null;
997991
for (const injector of this._injectors) await injector.close();
998992
this._injectors = [];
999993
}

js/src/translate/translate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ function wrapServiceWorkerCommand(method: string, params: ProtocolParams = {}, c
199199
}
200200

201201
let runtimeParams;
202+
let unwrap: "runtime" | "runtime_json" = "runtime";
202203
if (method === "Mod.evaluate") {
203204
const evaluateParams = params as ModCDPEvaluateParams;
204205
runtimeParams = wrapModCDPEvaluate({
@@ -215,13 +216,14 @@ function wrapServiceWorkerCommand(method: string, params: ProtocolParams = {}, c
215216
params,
216217
((params as ModCDPCustomPayload).cdpSessionId as string) ?? cdpSessionId,
217218
);
219+
unwrap = "runtime_json";
218220
}
219221

220222
return [
221223
{
222224
method: "Runtime.callFunctionOn",
223225
params: runtimeParams,
224-
unwrap: method.startsWith("Mod.") ? ("runtime" as const) : ("runtime_json" as const),
226+
unwrap,
225227
},
226228
];
227229
}

js/test/test.ExtensionInjector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ test("ExtensionInjector keeps the ModCDP service worker alive through offscreen
135135
{ expression: "globalThis.ModCDP?.__ModCDPServerVersion", returnByValue: true },
136136
session_id,
137137
);
138-
assert.equal((version.result as { value?: unknown }).value, 1);
138+
assert.equal((version.result as { value?: unknown }).value, 2);
139139
} finally {
140140
await cdp.close();
141141
await injector.close();

js/test/test.ModCDPClient.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,19 +293,19 @@ test("ModCDPClient defaults launched ModCDP-server upstreams to extension auto",
293293
}
294294
});
295295

296-
test("ModCDPClient rejects unknown component modes at their owning factory boundary", () => {
297-
assert.throws(
296+
test("ModCDPClient rejects unknown component modes at their owning factory boundary", async () => {
297+
await assert.rejects(
298298
() =>
299299
new ModCDPClient({
300300
upstream: { upstream_mode: "bogus" as any },
301301
})._upstreamTransport(),
302302
/unknown upstream\.upstream_mode=bogus/,
303303
);
304-
assert.throws(
304+
await assert.rejects(
305305
() => new ModCDPClient({ launcher: { launcher_mode: "bogus" as any } })._browserLauncher(),
306306
/unknown launcher\.launcher_mode=bogus/,
307307
);
308-
assert.throws(
308+
await assert.rejects(
309309
() => new ModCDPClient({ injector: { injector_mode: "bogus" as any } })._injectorsForConfig(),
310310
/unknown injector\.injector_mode=bogus/,
311311
);

js/test/test.ReverseWebSocketUpstreamTransport.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ test("reversews upstream accepts a real extension reverse connection and routes
135135
const reverse = new ModCDPClient({
136136
launcher: {
137137
launcher_mode: "local",
138-
launcher_options: { headless: true, sandbox: process.platform !== "linux" },
138+
launcher_options: {
139+
headless: process.platform === "linux" && !process.env.DISPLAY,
140+
sandbox: process.platform !== "linux",
141+
},
139142
},
140143
upstream: { upstream_mode: "reversews", upstream_reversews_bind: reverse_bind },
141144
injector: {

js/test/test.translate.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ test("translate routes, wraps, and unwraps ModCDP protocol messages deterministi
2828
assert.match(String(wrapped.steps[0]?.params.functionDeclaration), /attachToSession\("session-1"\)/);
2929
assert.equal(wrapped.steps[0]?.unwrap, "runtime");
3030

31+
const configured = wrapCommandIfNeeded("Mod.configure", { server: { server_routes: { "*.*": "loopback_cdp" } } });
32+
assert.equal(configured.steps[0]?.unwrap, "runtime_json");
33+
3134
assert.deepEqual(unwrapResponseIfNeeded({ result: { type: "object", value: { ok: true } } }, "runtime"), {
3235
ok: true,
3336
});

0 commit comments

Comments
 (0)