diff --git a/server/cmd/wrapper/snapshot_start_page.go b/server/cmd/wrapper/snapshot_start_page.go index 8712ec02..b1c25afe 100644 --- a/server/cmd/wrapper/snapshot_start_page.go +++ b/server/cmd/wrapper/snapshot_start_page.go @@ -43,7 +43,7 @@ func prepareSnapshotStartPage(ctx context.Context, internalPort string) (retErr return err } navCtx, cancel := context.WithTimeout(ctx, 20*time.Second) - navErr := cdpclient.DispatchStartURLAndWait(navCtx, devtoolsURL, snapshotStartPageURL) + navErr := cdpclient.DispatchStartURLAndWait(navCtx, devtoolsURL, "chrome://newtab/", snapshotStartPageURL) cancel() cleanupErr := cleanupSeedEnvoyIfStarted(seedEnvoyStarted) diff --git a/server/lib/cdpclient/cdpclient.go b/server/lib/cdpclient/cdpclient.go index cb0135a7..a59073c5 100644 --- a/server/lib/cdpclient/cdpclient.go +++ b/server/lib/cdpclient/cdpclient.go @@ -302,10 +302,10 @@ func DispatchStartURL(ctx context.Context, devtoolsURL, url string) error { return nil } -// DispatchStartURLAndWait navigates the user-facing page and waits until the -// destination has loaded without resolving to Chrome's network error page. -func DispatchStartURLAndWait(ctx context.Context, devtoolsURL, destination string) error { - if err := DispatchStartURL(ctx, devtoolsURL, destination); err != nil { +// DispatchStartURLAndWait navigates through navigationURL and waits for +// destination to load without resolving to Chrome's network error page. +func DispatchStartURLAndWait(ctx context.Context, devtoolsURL, navigationURL, destination string) error { + if err := DispatchStartURL(ctx, devtoolsURL, navigationURL); err != nil { return err } @@ -369,7 +369,7 @@ func DispatchStartURLAndWait(ctx context.Context, devtoolsURL, destination strin return nil } if strings.HasPrefix(lastState.URL, "chrome-error://") && time.Since(lastNavigate) >= 250*time.Millisecond { - _, _ = c.send(ctx, "Page.navigate", map[string]any{"url": destination}, attach.SessionID) + _, _ = c.send(ctx, "Page.navigate", map[string]any{"url": navigationURL}, attach.SessionID) lastNavigate = time.Now() } } diff --git a/server/lib/cdpclient/cdpclient_test.go b/server/lib/cdpclient/cdpclient_test.go index 636f0c14..8154b361 100644 --- a/server/lib/cdpclient/cdpclient_test.go +++ b/server/lib/cdpclient/cdpclient_test.go @@ -250,10 +250,10 @@ func TestDispatchStartURLAndWait(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - err := DispatchStartURLAndWait(ctx, url, "https://start.duckduckgo.com/") + err := DispatchStartURLAndWait(ctx, url, "chrome://newtab/", "https://start.duckduckgo.com/") require.NoError(t, err) assert.True(t, f.navigateCalled) - assert.Equal(t, "https://start.duckduckgo.com/", f.navigateURL) + assert.Equal(t, "chrome://newtab/", f.navigateURL) }) t.Run("retries a failed initial navigation", func(t *testing.T) { @@ -274,9 +274,10 @@ func TestDispatchStartURLAndWait(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) defer cancel() - err := DispatchStartURLAndWait(ctx, url, "https://start.duckduckgo.com/") + err := DispatchStartURLAndWait(ctx, url, "chrome://newtab/", "https://start.duckduckgo.com/") require.NoError(t, err) assert.GreaterOrEqual(t, f.navigateCalls, 2) + assert.Equal(t, "chrome://newtab/", f.navigateURL) }) t.Run("times out on Chrome error page", func(t *testing.T) { @@ -289,7 +290,7 @@ func TestDispatchStartURLAndWait(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) defer cancel() - err := DispatchStartURLAndWait(ctx, url, "https://start.duckduckgo.com/") + err := DispatchStartURLAndWait(ctx, url, "chrome://newtab/", "https://start.duckduckgo.com/") require.Error(t, err) assert.Contains(t, err.Error(), "chrome-error://chromewebdata/") })