-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdevtools.go
More file actions
39 lines (32 loc) · 980 Bytes
/
Copy pathdevtools.go
File metadata and controls
39 lines (32 loc) · 980 Bytes
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
package main
import (
"log"
"net/http"
"net/url"
"github.com/aqa-alex/selenwright/session"
)
func handleDevtoolsWebSocket(w http.ResponseWriter, r *http.Request, requestId uint64, sid string, remainingPath string, sess *session.Session) {
devtoolsHostPort := sess.HostPort.Devtools
if devtoolsHostPort == "" {
log.Printf("[%d] [DEVTOOLS_DISABLED] [%s]", requestId, sid)
http.Error(w, "DevTools are not available for this session", http.StatusBadGateway)
return
}
upstreamURL := &url.URL{
Scheme: "ws",
Host: devtoolsHostPort,
Path: remainingPath,
RawQuery: r.URL.RawQuery,
}
log.Printf("[%d] [DEVTOOLS] [%s] [%s]", requestId, sid, remainingPath)
err := proxyWebSocket(w, r, upstreamURL, func() {
touchWatchdog(sess)
}, func() {
touchWatchdog(sess)
})
if err == nil {
log.Printf("[%d] [DEVTOOLS_SESSION_CLOSED] [%s]", requestId, sid)
return
}
log.Printf("[%d] [DEVTOOLS_CLIENT_DISCONNECTED] [%s] [%v]", requestId, sid, err)
}