@@ -45,31 +45,29 @@ Manager by checking the error channel:
4545 // Manager is closed.
4646 }()
4747
48- # Manual session management
48+ # Manual session management (flattened protocol)
4949
50- For more control, sessions can be created directly via rpcc.NewSession
51- without using the Manager:
50+ For more control, flattened sessions can be created directly via rpcc.NewSession
51+ without using the Manager.
5252
53- reply, err := c.Target.AttachToTarget(ctx,
54- target.NewAttachToTargetArgs(targetID).SetFlatten(true))
53+ reply, err := c.Target.AttachToTarget(ctx, target.NewAttachToTargetArgs(targetID).SetFlatten(true))
5554 if err != nil {
5655 // Handle error.
5756 }
5857
59- sessionConn, err := rpcc.NewSession(conn, string(reply.SessionID),
60- rpcc.WithSessionClose(func(ctx context.Context) error {
61- return c.Target.DetachFromTarget(ctx,
62- target.NewDetachFromTargetArgs().SetSessionID(reply.SessionID))
63- }))
58+ sessConn, err := rpcc.NewSession(conn, string(reply.SessionID), rpcc.WithSessionClose(func(ctx context.Context) error {
59+ args := target.NewDetachFromTargetArgs().SetSessionID(reply.SessionID)
60+ return c.Target.DetachFromTarget(ctx, args)
61+ }))
6462 if err != nil {
6563 // Handle error.
6664 }
67- defer sessionConn .Close()
65+ defer sessConn .Close()
6866
69- sessionClient := cdp.NewClient(sessionConn )
67+ sessClient := cdp.NewClient(sessConn )
7068 // ...
7169
72- The WithSessionClose callback handles detachment when you close the session.
70+ The WithSessionClose function handles detachment when you close the session.
7371Note that Chrome may also detach sessions (e.g. when a target is destroyed).
7472For short-lived operations this can be ignored, but for long-lived sessions
7573you should listen for Target.DetachedFromTarget events or use the Manager.
0 commit comments