-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
listeners.go
43 lines (38 loc) · 1.23 KB
/
listeners.go
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
39
40
41
42
43
package biloba
import (
"github.com/chromedp/cdproto/browser"
"github.com/chromedp/cdproto/cdp"
"github.com/chromedp/cdproto/page"
"github.com/chromedp/cdproto/runtime"
"github.com/chromedp/chromedp"
)
func (b *Biloba) configureDownloadBehaviorForAllTabsWithBrowserContextID(browserContextId cdp.BrowserContextID) {
for _, tab := range b.AllTabs() {
if tab.browserContextID == browserContextId {
tab.configureDownloadBehavior()
}
}
}
func (b *Biloba) configureDownloadBehavior() {
chromedp.Run(b.Context, browser.SetDownloadBehavior(browser.SetDownloadBehaviorBehaviorAllowAndName).
WithDownloadPath(b.root.downloadDir).
WithEventsEnabled(true).
WithBrowserContextID(b.browserContextID))
}
func (b *Biloba) setUpListeners() {
b.configureDownloadBehavior()
chromedp.ListenTarget(b.Context, func(ev interface{}) {
switch ev := ev.(type) {
case *page.EventJavascriptDialogOpening:
b.handleEventJavascriptDialogOpening(ev)
case *runtime.EventConsoleAPICalled:
b.handleEventConsoleAPICalled(ev)
case *page.EventFrameNavigated:
b.handleEventFrameNavigated(ev)
case *browser.EventDownloadWillBegin:
b.handleEventDownloadWillBegin(ev)
case *browser.EventDownloadProgress:
b.handleEventDownloadProgress(ev)
}
})
}