From 0d04e0b72d6bab22b9f715740dd48af5e32d1b4e Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Fri, 24 Jan 2025 14:02:08 +0100 Subject: [PATCH] fix: rely on frameSubtreeWillBeDetached to emit contextDestroyed events (#3029) Co-authored-by: browser-automation-bot <133232582+browser-automation-bot@users.noreply.github.com> --- src/bidiMapper/modules/cdp/CdpTargetManager.ts | 12 ------------ .../modules/context/BrowsingContextImpl.ts | 4 +++- .../context_destroyed/context_destroyed.py.ini | 6 ------ .../context_destroyed/context_destroyed.py.ini | 6 ------ .../context_destroyed/context_destroyed.py.ini | 6 ------ 5 files changed, 3 insertions(+), 31 deletions(-) delete mode 100644 wpt-metadata/chromedriver/headful/webdriver/tests/bidi/browsing_context/context_destroyed/context_destroyed.py.ini delete mode 100644 wpt-metadata/chromedriver/headless/webdriver/tests/bidi/browsing_context/context_destroyed/context_destroyed.py.ini delete mode 100644 wpt-metadata/mapper/headless/webdriver/tests/bidi/browsing_context/context_destroyed/context_destroyed.py.ini diff --git a/src/bidiMapper/modules/cdp/CdpTargetManager.ts b/src/bidiMapper/modules/cdp/CdpTargetManager.ts index 910bd35e8c..aa29dba421 100644 --- a/src/bidiMapper/modules/cdp/CdpTargetManager.ts +++ b/src/bidiMapper/modules/cdp/CdpTargetManager.ts @@ -116,10 +116,6 @@ export class CdpTargetManager { 'Page.frameAttached', this.#handleFrameAttachedEvent.bind(this), ); - cdpClient.on( - 'Page.frameDetached', - this.#handleFrameDetachedEvent.bind(this), - ); cdpClient.on( 'Page.frameSubtreeWillBeDetached', this.#handleFrameSubtreeWillBeDetached.bind(this), @@ -149,14 +145,6 @@ export class CdpTargetManager { } } - #handleFrameDetachedEvent(params: Protocol.Page.FrameDetachedEvent) { - // In case of OOPiF no need in deleting BrowsingContext. - if (params.reason === 'swap') { - return; - } - this.#browsingContextStorage.findContext(params.frameId)?.dispose(true); - } - #handleFrameSubtreeWillBeDetached( params: Protocol.Page.FrameSubtreeWillBeDetachedEvent, ) { diff --git a/src/bidiMapper/modules/context/BrowsingContextImpl.ts b/src/bidiMapper/modules/context/BrowsingContextImpl.ts index 732b8126c7..535ff17965 100644 --- a/src/bidiMapper/modules/context/BrowsingContextImpl.ts +++ b/src/bidiMapper/modules/context/BrowsingContextImpl.ts @@ -202,7 +202,6 @@ export class BrowsingContextImpl { dispose(emitContextDestroyed: boolean) { this.#navigationTracker.dispose(); - this.#deleteAllChildren(); this.#realmStorage.deleteRealms({ browsingContextId: this.id, @@ -227,6 +226,9 @@ export class BrowsingContextImpl { ); } + // Dispose children after the events are emitted. + this.#deleteAllChildren(); + this.#eventManager.clearBufferedEvents(this.id); this.#browsingContextStorage.deleteContextById(this.id); diff --git a/wpt-metadata/chromedriver/headful/webdriver/tests/bidi/browsing_context/context_destroyed/context_destroyed.py.ini b/wpt-metadata/chromedriver/headful/webdriver/tests/bidi/browsing_context/context_destroyed/context_destroyed.py.ini deleted file mode 100644 index 0d6a5ccffe..0000000000 --- a/wpt-metadata/chromedriver/headful/webdriver/tests/bidi/browsing_context/context_destroyed/context_destroyed.py.ini +++ /dev/null @@ -1,6 +0,0 @@ -[context_destroyed.py] - [test_nested_iframes_delete_top_iframe] - expected: FAIL - - [test_iframe_destroy_parent] - expected: FAIL diff --git a/wpt-metadata/chromedriver/headless/webdriver/tests/bidi/browsing_context/context_destroyed/context_destroyed.py.ini b/wpt-metadata/chromedriver/headless/webdriver/tests/bidi/browsing_context/context_destroyed/context_destroyed.py.ini deleted file mode 100644 index 0d6a5ccffe..0000000000 --- a/wpt-metadata/chromedriver/headless/webdriver/tests/bidi/browsing_context/context_destroyed/context_destroyed.py.ini +++ /dev/null @@ -1,6 +0,0 @@ -[context_destroyed.py] - [test_nested_iframes_delete_top_iframe] - expected: FAIL - - [test_iframe_destroy_parent] - expected: FAIL diff --git a/wpt-metadata/mapper/headless/webdriver/tests/bidi/browsing_context/context_destroyed/context_destroyed.py.ini b/wpt-metadata/mapper/headless/webdriver/tests/bidi/browsing_context/context_destroyed/context_destroyed.py.ini deleted file mode 100644 index 0d6a5ccffe..0000000000 --- a/wpt-metadata/mapper/headless/webdriver/tests/bidi/browsing_context/context_destroyed/context_destroyed.py.ini +++ /dev/null @@ -1,6 +0,0 @@ -[context_destroyed.py] - [test_nested_iframes_delete_top_iframe] - expected: FAIL - - [test_iframe_destroy_parent] - expected: FAIL