Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/playwright-core/src/server/bidi/bidiPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,17 @@ export class BidiPage implements PageDelegate {

private _onNavigationStarted(params: bidi.BrowsingContext.NavigationInfo) {
const frameId = params.context;
this._page.frameManager.frameRequestedNavigation(frameId, params.navigation!);
this._page.frameManager.frameRequestedNavigation(frameId, params.navigation || undefined);
}

private _onNavigationCommitted(params: bidi.BrowsingContext.NavigationInfo) {
const frameId = params.context;
const frame = this._page.frameManager.frame(frameId)!;
const frame = this._page.frameManager.frame(frameId);
if (!frame)
return;
this._browserContext.doGrantGlobalPermissionsForURL(params.url).catch(error => debugLogger.log('error', error));
this._page.frameManager.frameCommittedNewDocumentNavigation(frameId, params.url, frame._name, params.navigation!, /* initial */ false);
if (params.navigation)
this._page.frameManager.frameCommittedNewDocumentNavigation(frameId, params.url, frame._name, params.navigation, /* initial */ false);
}

private _onDomContentLoaded(params: bidi.BrowsingContext.NavigationInfo) {
Expand Down
24 changes: 24 additions & 0 deletions tests/page/page-goto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,30 @@ it('should navigate to about:blank', async ({ page, server }) => {
expect(response).toBe(null);
});

it('should handle navigation with null navigation id in BiDi', async ({ page, server, isBidi }) => {
// This test verifies that BiDi navigation events with null navigation are handled gracefully.
// In BiDi, navigation can be null for same-document navigations and some edge cases.
// Without proper handling, null navigation would be passed to frameManager methods
// that expect string or undefined, causing issues.
it.skip(!isBidi, 'BiDi-specific test');

// Test 1: Navigate to about:blank (might have null navigation in some BiDi implementations)
await page.goto('about:blank');
expect(page.url()).toBe('about:blank');

// Test 2: Navigate to a real page
await page.goto(server.EMPTY_PAGE);
expect(page.url()).toBe(server.EMPTY_PAGE);

// Test 3: Use history.pushState (same-document navigation, navigation is null in BiDi)
await page.evaluate(() => history.pushState({}, '', '/pushed'));
expect(page.url()).toBe(server.PREFIX + '/pushed');

// Test 4: Navigate back
await page.goBack();
expect(page.url()).toBe(server.EMPTY_PAGE);
});

it('should return response when page changes its URL after load', async ({ page, server }) => {
const response = await page.goto(server.PREFIX + '/historyapi.html');
expect(response.status()).toBe(200);
Expand Down
Loading