Skip to content

Commit 4112a77

Browse files
committed
docs(session): clarify manual mode is flattened only
1 parent 29a00ef commit 4112a77

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

session/doc.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
7371
Note that Chrome may also detach sessions (e.g. when a target is destroyed).
7472
For short-lived operations this can be ignored, but for long-lived sessions
7573
you should listen for Target.DetachedFromTarget events or use the Manager.

0 commit comments

Comments
 (0)