mirror of
https://github.com/browseros-ai/BrowserOS.git
synced 2026-05-19 11:31:03 +00:00
git-subtree-dir: packages/browseros-agent git-subtree-mainline:8f148d0918git-subtree-split:90bd4be300
33 lines
558 B
Go
33 lines
558 B
Go
package browser
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
func WaitForCDP(ctx context.Context, port int, maxAttempts int) bool {
|
|
client := &http.Client{Timeout: time.Second}
|
|
url := fmt.Sprintf("http://127.0.0.1:%d/json/version", port)
|
|
|
|
for range maxAttempts {
|
|
if ctx.Err() != nil {
|
|
return false
|
|
}
|
|
resp, err := client.Get(url)
|
|
if err == nil {
|
|
resp.Body.Close()
|
|
if resp.StatusCode == 200 {
|
|
return true
|
|
}
|
|
}
|
|
select {
|
|
case <-ctx.Done():
|
|
return false
|
|
case <-time.After(500 * time.Millisecond):
|
|
}
|
|
}
|
|
return false
|
|
}
|