crash fix
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user