diff --git a/src/bidiMapper/modules/context/BrowsingContextImpl.ts b/src/bidiMapper/modules/context/BrowsingContextImpl.ts index 7018a85ae..1197c0546 100644 --- a/src/bidiMapper/modules/context/BrowsingContextImpl.ts +++ b/src/bidiMapper/modules/context/BrowsingContextImpl.ts @@ -35,7 +35,7 @@ import {Deferred} from '../../../utils/Deferred.js'; import {EventEmitter} from '../../../utils/EventEmitter.js'; import {type LoggerFn, LogType} from '../../../utils/log.js'; import {inchesFromCm} from '../../../utils/unitConversions.js'; -import {urlMatchesAboutBlank} from '../../../utils/UrlHelpers'; +import {urlMatchesAboutBlank} from '../../../utils/UrlHelpers.js'; import {uuidv4} from '../../../utils/uuid.js'; import type {CdpTarget} from '../cdp/CdpTarget.js'; import type {Realm} from '../script/Realm.js'; @@ -99,12 +99,6 @@ class NavigationState extends EventEmitter { } } - isStarted() { - return this.#states[ - ChromiumBidi.BrowsingContext.EventNames.NavigationStarted - ]; - } - markStarted() { this.#completeAndNotify( ChromiumBidi.BrowsingContext.EventNames.NavigationStarted, @@ -324,8 +318,6 @@ class NavigationTracker { } frameScheduledNavigation(url: string): void { - // If `Page.frameScheduledNavigation` is not guaranteed to be emitted, but if it - // does, it never goes before `Page.frameScheduledNavigation`. // Signals that it's a new navigation: // 1. The `Page.frameStartedLoading` was already emitted. // 2. The `Page.frameScheduledNavigation` was already emitted. @@ -1152,6 +1144,9 @@ export class BrowsingContextImpl { if (navigationResult === NavigationWaitResult.FAILED) { throw new UnknownErrorException('Navigation failed'); } + if (navigationResult === NavigationWaitResult.ABORTED) { + throw new UnknownErrorException('Navigation aborted'); + } return { navigation: navigation.navigationId, @@ -1503,6 +1498,7 @@ export class BrowsingContextImpl { `No history entry at delta ${delta}`, ); } + this.#navigationTracker.createNavigation(entry.url); await this.#cdpTarget.cdpClient.sendCommand('Page.navigateToHistoryEntry', { entryId: entry.id, }); diff --git a/tests/browsing_context/test_close.py b/tests/browsing_context/test_close.py index c2a5242ef..6bb188c7a 100644 --- a/tests/browsing_context/test_close.py +++ b/tests/browsing_context/test_close.py @@ -257,8 +257,7 @@ async def test_browsingContext_navigate_prompt(websocket, context_id, html, assert resp == AnyExtending({ 'error': 'unknown error', 'id': navigate_command_id, - 'message': 'net::ERR_ABORTED', - 'stacktrace': ANY_STR, + 'message': 'Navigation aborted', 'type': 'error', }) # Handle prompt command expected to succeed. diff --git a/tests/browsing_context/test_navigate.py b/tests/browsing_context/test_navigate.py index ca2500dec..21786d5a1 100644 --- a/tests/browsing_context/test_navigate.py +++ b/tests/browsing_context/test_navigate.py @@ -40,16 +40,16 @@ async def test_browsingContext_navigateWaitInteractive_redirect( navigation_aborted_event] = await read_sorted_messages(2) assert navigation_result == AnyExtending({ 'id': command_id, - 'type': 'success' + 'type': 'error', + 'message': 'Navigation aborted' }) - initial_navigation_id = navigation_result['result']['navigation'] assert navigation_aborted_event == AnyExtending({ 'method': 'browsingContext.navigationAborted', 'type': 'event', 'params': { 'context': context_id, - 'navigation': initial_navigation_id, + 'navigation': ANY_UUID, 'timestamp': ANY_TIMESTAMP, 'url': initial_url } @@ -565,11 +565,10 @@ async def test_browsingContext_navigationStarted_browsingContextClosedBeforeNavi assert messages == [ { 'id': navigate_command_id, - 'result': { - 'navigation': ANY_UUID, - 'url': url_hang_forever, - }, - 'type': 'success', + 'error': 'unknown error', + 'message': 'Navigation aborted', + 'stacktrace': ANY_STR, + 'type': 'error', }, { 'id': close_command_id, @@ -613,10 +612,9 @@ async def test_browsingContext_navigationStarted_browsingContextClosedBeforeNavi @pytest.mark.asyncio -async def test_browsingContext_navigationStarted_navigateBeforeNavigationEnded_navigationSucceeded( +async def test_browsingContext_navigationStarted_navigateBeforeNavigationEnded_navigationFailed( websocket, context_id, read_sorted_messages, url_hang_forever, url_example): - pytest.xfail("Not implemented yet") await subscribe(websocket, ["browsingContext.navigationAborted"]) first_navigation_command_id = await send_JSON_command( @@ -643,11 +641,10 @@ async def test_browsingContext_navigationStarted_navigateBeforeNavigationEnded_n assert messages == [ { 'id': first_navigation_command_id, - 'result': { - 'navigation': ANY_UUID, - 'url': url_hang_forever, - }, - 'type': 'success', + 'type': 'error', + 'error': 'unknown error', + 'message': 'Navigation aborted', + 'stacktrace': ANY_STR }, { 'id': second_navigation_command_id, @@ -669,10 +666,6 @@ async def test_browsingContext_navigationStarted_navigateBeforeNavigationEnded_n }, ] - # Assert the first navigation aborted. - assert messages[0]['result']['navigation'] == messages[2]['params'][ - 'navigation'] - @pytest.mark.asyncio async def test_browsingContext_navigationStarted_sameDocumentNavigation( @@ -780,11 +773,7 @@ async def navigate(): if capabilities.get('acceptInsecureCerts'): await navigate() else: - with pytest.raises(Exception, - match=str({ - 'error': 'unknown error', - 'message': 'net::ERR_CERT_AUTHORITY_INVALID' - })): + with pytest.raises(Exception): await navigate()