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
This commit is contained in:
daijro 2024-08-17 21:00:03 -05:00
parent a78c5a2d91
commit f8f868307a
2 changed files with 11 additions and 9 deletions

View file

@ -292,7 +292,7 @@ Miscellaneous (WebGl spoofing, battery status, etc)
- Custom implementation of Playwright for the latest Firefox - Custom implementation of Playwright for the latest Firefox
- Various config patches to evade bot detection - Various config patches to evade bot detection
- Removed leaking Playwright patches: - Removed leaking Playwright patches:
- Fixes `content-document-global-created` observer leak - Fixes frame execution context leaks
- Fixes `navigator.webdriver` detection - Fixes `navigator.webdriver` detection
- Removed potentially leaking anti-zoom/meta viewport handling patches - Removed potentially leaking anti-zoom/meta viewport handling patches
- Re-enable fission content isolation - Re-enable fission content isolation

View file

@ -68,6 +68,7 @@ class FrameTree {
frame._pendingNavigationId = helper.toProtocolNavigationId(loadIdentifier); frame._pendingNavigationId = helper.toProtocolNavigationId(loadIdentifier);
this.emit(FrameTree.Events.NavigationStarted, frame); this.emit(FrameTree.Events.NavigationStarted, frame);
}, 'juggler-navigation-started-renderer'), }, '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(this._onDOMWindowCreated.bind(this), 'juggler-dom-window-reused'),
helper.addObserver((browsingContext, topic, why) => { helper.addObserver((browsingContext, topic, why) => {
this._onBrowsingContextAttached(browsingContext); this._onBrowsingContextAttached(browsingContext);
@ -558,20 +559,21 @@ class Frame {
} }
_onGlobalObjectCleared() { _onGlobalObjectCleared() {
// Causing leaks.
const webSocketService = this._frameTree._webSocketEventService; const webSocketService = this._frameTree._webSocketEventService;
if (this._webSocketListenerInnerWindowId && webSocketService.hasListenerFor(this._webSocketListenerInnerWindowId)) if (this._webSocketListenerInnerWindowId && webSocketService.hasListenerFor(this._webSocketListenerInnerWindowId))
webSocketService.removeListener(this._webSocketListenerInnerWindowId, this._webSocketListener); webSocketService.removeListener(this._webSocketListenerInnerWindowId, this._webSocketListener);
this._webSocketListenerInnerWindowId = this.domWindow().windowGlobalChild.innerWindowId; this._webSocketListenerInnerWindowId = this.domWindow().windowGlobalChild.innerWindowId;
webSocketService.addListener(this._webSocketListenerInnerWindowId, this._webSocketListener); 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._worldNameToContext.set('', this._runtime.createExecutionContext(this.domWindow(), this.domWindow(), {
this._runtime.destroyExecutionContext(context); // frameId: this._frameId,
this._worldNameToContext.clear(); // name: '',
// }));
this._worldNameToContext.set('', this._runtime.createExecutionContext(this.domWindow(), this.domWindow(), {
frameId: this._frameId,
name: '',
}));
for (const [name, world] of this._frameTree._isolatedWorlds) { for (const [name, world] of this._frameTree._isolatedWorlds) {
if (name) if (name)
this._createIsolatedContext(name); this._createIsolatedContext(name);