@@ -14,6 +14,7 @@ const Methods = enum {
1414 getBrowserContexts ,
1515 createBrowserContext ,
1616 createTarget ,
17+ closeTarget ,
1718};
1819
1920pub fn target (
@@ -32,6 +33,7 @@ pub fn target(
3233 .getBrowserContexts = > getBrowserContexts (alloc , id , scanner , ctx ),
3334 .createBrowserContext = > createBrowserContext (alloc , id , scanner , ctx ),
3435 .createTarget = > createTarget (alloc , id , scanner , ctx ),
36+ .closeTarget = > closeTarget (alloc , id , scanner , ctx ),
3537 };
3638}
3739
@@ -75,6 +77,8 @@ fn setAutoAttach(
7577 scanner : * std.json.Scanner ,
7678 ctx : * Ctx ,
7779) ! []const u8 {
80+
81+ // input
7882 const Params = struct {
7983 autoAttach : bool ,
8084 waitForDebuggerOnStart : bool ,
@@ -234,3 +238,55 @@ fn createTarget(
234238 };
235239 return result (alloc , id orelse msg .id .? , Resp , Resp {}, msg .sessionID );
236240}
241+
242+ fn closeTarget (
243+ alloc : std.mem.Allocator ,
244+ id : ? u16 ,
245+ scanner : * std.json.Scanner ,
246+ ctx : * Ctx ,
247+ ) ! []const u8 {
248+
249+ // input
250+ const Params = struct {
251+ targetId : []const u8 ,
252+ };
253+ const msg = try getMsg (alloc , Params , scanner );
254+
255+ // output
256+ const Resp = struct {
257+ success : bool = true ,
258+ };
259+ const res = try result (alloc , id orelse msg .id .? , Resp , Resp {}, null );
260+ try server .sendSync (ctx , res );
261+
262+ // events
263+ const InspectorDetached = struct {
264+ reason : []const u8 = "Render process gone." ,
265+ };
266+ try cdp .sendEvent (
267+ alloc ,
268+ ctx ,
269+ "Inspector.detached" ,
270+ InspectorDetached ,
271+ .{},
272+ msg .sessionID orelse cdp .ContextSessionID ,
273+ );
274+
275+ const TargetDetached = struct {
276+ sessionId : []const u8 ,
277+ targetId : []const u8 ,
278+ };
279+ try cdp .sendEvent (
280+ alloc ,
281+ ctx ,
282+ "Target.detachedFromTarget" ,
283+ TargetDetached ,
284+ .{
285+ .sessionId = msg .sessionID orelse cdp .ContextSessionID ,
286+ .targetId = msg .params .? .targetId ,
287+ },
288+ null ,
289+ );
290+
291+ return "" ;
292+ }
0 commit comments