Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

feat: fps rate limiting on screencast (default 1fps)

Marioa2d357db759c
diff --git a/dashboard.go b/dashboard.go
index 308f8e19..799a930f 100644
--- a/dashboard.go
+++ b/dashboard.go
@@ -1138,7 +1138,7 @@ async function viewInstanceLive(id, port) {
}
function startScreencastDirect(tabId, port) {
- const wsUrl = 'ws://localhost:' + port + '/screencast?tabId=' + tabId + '&quality=50&maxWidth=800';
+ const wsUrl = 'ws://localhost:' + port + '/screencast?tabId=' + tabId + '&quality=30&maxWidth=800&fps=1';
const socket = new WebSocket(wsUrl);
socket.binaryType = 'arraybuffer';
screencastSockets[tabId] = socket;
@@ -1223,7 +1223,7 @@ async function refreshTabs() {
function startScreencast(tabId) {
const proto = location.protocol === 'https:' ? 'wss:' : 'ws:';
- const wsUrl = proto + '//' + location.host + '/screencast?tabId=' + tabId + '&quality=50&maxWidth=800';
+ const wsUrl = proto + '//' + location.host + '/screencast?tabId=' + tabId + '&quality=30&maxWidth=800&fps=1';
const socket = new WebSocket(wsUrl);
socket.binaryType = 'arraybuffer';
screencastSockets[tabId] = socket;
diff --git a/screencast.go b/screencast.go
index c3fdd9f3..e498442d 100644
--- a/screencast.go
+++ b/screencast.go
@@ -49,9 +49,14 @@ func (b *Bridge) handleScreencast(w http.ResponseWriter, r *http.Request) {
tab = &TabEntry{ctx: tabCtx}
}
- quality := queryParamInt(r, "quality", 40)
+ quality := queryParamInt(r, "quality", 30)
maxWidth := queryParamInt(r, "maxWidth", 800)
- everyNth := queryParamInt(r, "everyNthFrame", 2)
+ everyNth := queryParamInt(r, "everyNthFrame", 4)
+ fps := queryParamInt(r, "fps", 1) // default 1 fps to save bandwidth
+ if fps > 30 {
+ fps = 30
+ }
+ minFrameInterval := time.Second / time.Duration(fps)
// Upgrade to WebSocket
conn, _, _, err := ws.UpgradeHTTP(r, w)
@@ -71,16 +76,11 @@ func (b *Bridge) handleScreencast(w http.ResponseWriter, r *http.Request) {
var once sync.Once
done := make(chan struct{})
- // Listen for screencast frames
+ // Listen for screencast frames with rate limiting
+ var lastFrame time.Time
chromedp.ListenTarget(ctx, func(ev interface{}) {
switch e := ev.(type) {
case *page.EventScreencastFrame:
- // Decode base64 frame data
- data, err := base64.StdEncoding.DecodeString(e.Data)
- if err != nil {
- return
- }
-
// Ack the frame so Chrome sends the next one
go func() {
_ = chromedp.Run(ctx,
@@ -90,6 +90,19 @@ func (b *Bridge) handleScreencast(w http.ResponseWriter, r *http.Request) {
)
}()
+ // Rate limit: skip frames if too fast
+ now := time.Now()
+ if now.Sub(lastFrame) < minFrameInterval {
+ return
+ }
+ lastFrame = now
+
+ // Decode base64 frame data
+ data, err := base64.StdEncoding.DecodeString(e.Data)
+ if err != nil {
+ return
+ }
+
// Non-blocking send
select {
case frameCh <- data: