From f8f868307a8246414e5eb50465e41973230c2158 Mon Sep 17 00:00:00 2001 From: daijro Date: Sat, 17 Aug 2024 21:00:03 -0500 Subject: [PATCH] Fix frame execution contexts leak - Prevents the creation of execution contexts in frames on content-document-global-created. - Also fixes input events not working in Playwright --- README.md | 2 +- additions/juggler/content/FrameTree.js | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b4712c9..df44641 100644 --- a/README.md +++ b/README.md @@ -292,7 +292,7 @@ Miscellaneous (WebGl spoofing, battery status, etc) - Custom implementation of Playwright for the latest Firefox - Various config patches to evade bot detection - Removed leaking Playwright patches: - - Fixes `content-document-global-created` observer leak + - Fixes frame execution context leaks - Fixes `navigator.webdriver` detection - Removed potentially leaking anti-zoom/meta viewport handling patches - Re-enable fission content isolation diff --git a/additions/juggler/content/FrameTree.js b/additions/juggler/content/FrameTree.js index 55c52fb..e4c4f8d 100644 --- a/additions/juggler/content/FrameTree.js +++ b/additions/juggler/content/FrameTree.js @@ -68,6 +68,7 @@ class FrameTree { frame._pendingNavigationId = helper.toProtocolNavigationId(loadIdentifier); this.emit(FrameTree.Events.NavigationStarted, frame); }, 'juggler-navigation-started-renderer'), + helper.addObserver(this._onDOMWindowCreated.bind(this), 'content-document-global-created'), helper.addObserver(this._onDOMWindowCreated.bind(this), 'juggler-dom-window-reused'), helper.addObserver((browsingContext, topic, why) => { this._onBrowsingContextAttached(browsingContext); @@ -558,20 +559,21 @@ class Frame { } _onGlobalObjectCleared() { + // Causing leaks. const webSocketService = this._frameTree._webSocketEventService; if (this._webSocketListenerInnerWindowId && webSocketService.hasListenerFor(this._webSocketListenerInnerWindowId)) webSocketService.removeListener(this._webSocketListenerInnerWindowId, this._webSocketListener); this._webSocketListenerInnerWindowId = this.domWindow().windowGlobalChild.innerWindowId; webSocketService.addListener(this._webSocketListenerInnerWindowId, this._webSocketListener); + // Camoufox: Causes leaks. + // for (const context of this._worldNameToContext.values()) + // this._runtime.destroyExecutionContext(context); + // this._worldNameToContext.clear(); - for (const context of this._worldNameToContext.values()) - this._runtime.destroyExecutionContext(context); - this._worldNameToContext.clear(); - - this._worldNameToContext.set('', this._runtime.createExecutionContext(this.domWindow(), this.domWindow(), { - frameId: this._frameId, - name: '', - })); + // this._worldNameToContext.set('', this._runtime.createExecutionContext(this.domWindow(), this.domWindow(), { + // frameId: this._frameId, + // name: '', + // })); for (const [name, world] of this._frameTree._isolatedWorlds) { if (name) this._createIsolatedContext(name);