summaryrefslogtreecommitdiff
path: root/vendor/github.com/playwright-community/playwright-go/cdp_session.go
blob: e9bba82db1a5d449d60e073a11c0fbe5b7a869fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package playwright

type cdpSessionImpl struct {
	channelOwner
}

func (c *cdpSessionImpl) Detach() error {
	_, err := c.channel.Send("detach")
	return err
}

func (c *cdpSessionImpl) Send(method string, params map[string]interface{}) (interface{}, error) {
	result, err := c.channel.Send("send", map[string]interface{}{
		"method": method,
		"params": params,
	})
	if err != nil {
		return nil, err
	}

	return result, err
}

func (c *cdpSessionImpl) onEvent(params map[string]interface{}) {
	c.Emit(params["method"].(string), params["params"])
}

func newCDPSession(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *cdpSessionImpl {
	bt := &cdpSessionImpl{}

	bt.createChannelOwner(bt, parent, objectType, guid, initializer)

	bt.channel.On("event", func(params map[string]interface{}) {
		bt.onEvent(params)
	})

	return bt
}