crash fix

This commit is contained in:
Josh at WLTechBlog
2025-12-24 11:00:37 -07:00
parent 6f9839ee86
commit f09cdc2973
2 changed files with 77 additions and 38 deletions

View File

@@ -2596,6 +2596,15 @@ func (d *Daemon) loadURL(tabID, url string, timeout int) error {
}
d.debugLog("Got tab %s, starting navigation", tabID)
// Ensure page is fully initialized before using in goroutine
// This prevents "assignment to entry in nil map" panics in rod library
// See: https://github.com/go-rod/rod/issues/331
_, err = page.Info()
if err != nil {
d.debugLog("Warning: failed to initialize page %s: %v", tabID, err)
// Continue anyway, as the page might still work
}
if timeout > 0 {
// Use timeout for the URL loading
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
@@ -2606,6 +2615,12 @@ func (d *Daemon) loadURL(tabID, url string, timeout int) error {
// Execute the navigation in a goroutine
go func() {
defer func() {
if r := recover(); r != nil {
done <- fmt.Errorf("navigation panicked: %v", r)
}
}()
err := page.Navigate(url)
if err != nil {
done <- fmt.Errorf("failed to navigate to URL: %w", err)