github.com/MontFerret/ferret@v0.18.0/pkg/drivers/cdp/network/events.go (about) 1 package network 2 3 import ( 4 "context" 5 6 "github.com/mafredri/cdp" 7 "github.com/mafredri/cdp/protocol/fetch" 8 "github.com/mafredri/cdp/protocol/network" 9 "github.com/mafredri/cdp/rpcc" 10 11 "github.com/MontFerret/ferret/pkg/drivers/cdp/events" 12 ) 13 14 var ( 15 responseReceivedEvent = events.New("response_received") 16 requestPausedEvent = events.New("request_paused") 17 ) 18 19 func createResponseReceivedStreamFactory(client *cdp.Client) events.SourceFactory { 20 return events.NewStreamSourceFactory(responseReceivedEvent, func(ctx context.Context) (rpcc.Stream, error) { 21 return client.Network.ResponseReceived(ctx) 22 }, func(stream rpcc.Stream) (interface{}, error) { 23 return stream.(network.ResponseReceivedClient).Recv() 24 }) 25 } 26 27 func createRequestPausedStreamFactory(client *cdp.Client) events.SourceFactory { 28 return events.NewStreamSourceFactory(requestPausedEvent, func(ctx context.Context) (rpcc.Stream, error) { 29 return client.Fetch.RequestPaused(ctx) 30 }, func(stream rpcc.Stream) (interface{}, error) { 31 return stream.(fetch.RequestPausedClient).Recv() 32 }) 33 }