session

package
v0.19.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package session implements a session Manager for establishing session connections to targets (via the Target domain). Session connections allow a single websocket connection (from the provided cdp.Client) to be used for communicating with multiple targets.

Initialize a new session Manager.

c := cdp.NewClient(conn) // cdp.Client with websocket connection.

m, err := session.NewManager(c)
if err != nil {
	// Handle error.
}
defer m.Close() // Cleanup.

Establish a new session connection to targetID.

pageConn, err := m.Dial(context.TODO(), targetID)
if err != nil {
	// Handle error.
}
defer pageConn.Close()

Use the session connection.

pageClient := cdp.NewClient(pageConn)
err = pageClient.Page.Enable(context.TODO())
// ...

If session connections are behaving unexpectedly, you can debug the session Manager by checking the error channel.

go func() {
	for err := range m.Err() {
		log.Println(err)
	}
	// Manager is closed.
}()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager establishes session connections to targets.

func NewManager

func NewManager(c *cdp.Client) (*Manager, error)

NewManager creates a new session Manager.

The cdp.Client will be used to listen to events and invoke commands on the Target domain. It will also be used by all rpcc.Conn created by Dial.

func (*Manager) Close

func (m *Manager) Close() error

Close closes the Manager and all active sessions. All rpcc.Conn created by Dial will be closed.

func (*Manager) Dial

func (m *Manager) Dial(ctx context.Context, id target.ID) (*rpcc.Conn, error)

Dial establishes a target session and creates a lightweight rpcc.Conn that uses SendMessageToTarget and ReceivedMessageFromTarget from the Target domain instead of a new websocket connection.

Dial will invoke AttachToTarget. Close (rpcc.Conn) will invoke DetachFromTarget.

func (*Manager) Err

func (m *Manager) Err() <-chan error

Err is a channel that blocks until the Manager encounters an error. The channel is closed if Manager is closed.

Errors could happen if the debug target sends events that cannot be decoded from JSON.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL