Skip to content

Commit

Permalink
Misc fixes beta.13
Browse files Browse the repository at this point in the history
- Fixed some memory enhancement prefs not setting correctly.
- Bfcache is now completely disabled. This should improve memory, but kills Playwright's page.go_back() and page.go_forward(). To re-enable this, set `browser.sessionhistory.max_entries` to the amount of pages you want to remember.
- Moved SanitizeOnShutdown policy to preferences instead. This unlocks clearOnShutdown preferences. #47
- Added experimental memorysaver property that clears all of the memory after each page.goto navigation. Helpful for datacenters running Camoufox, but could potentially break things.
- Cursor now starts in a random position on the screen
- Fixed screenshots not capturing the full window when a viewport is set by window.innerWidth and window.innerHeight.
  • Loading branch information
daijro committed Oct 24, 2024
1 parent 711b5b4 commit dc3c0bd
Show file tree
Hide file tree
Showing 6 changed files with 488 additions and 454 deletions.
18 changes: 10 additions & 8 deletions additions/juggler/TargetRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,11 @@ class PageTarget {
this._tab = tab;
this._linkedBrowser = tab.linkedBrowser;
this._browserContext = browserContext;
this._viewportSize = undefined;
// Set the viewport size to Camoufox's default value.
this._viewportSize = {
width: ChromeUtils.camouGetInt("window.innerWidth") || 1280,
height: ChromeUtils.camouGetInt("window.innerHeight") || 720,
};;
this._initialDPPX = this._linkedBrowser.browsingContext.overrideDPPX;
this._url = 'about:blank';
this._openerId = opener ? opener.id() : undefined;
Expand Down Expand Up @@ -570,14 +574,12 @@ class PageTarget {
// Otherwise, explicitly set page viewport prevales over browser context
// default viewport.

// Do not allow default viewport size if Camoufox set it first
// Camoufox is already handling viewport size, so we don't need to set it here.
if (
!this._viewportSize &&
this._browserContext.defaultViewportSize && (
ChromeUtils.camouGetInt("window.outerWidth") ||
ChromeUtils.camouGetInt("window.outerHeight") ||
ChromeUtils.camouGetInt("window.innerWidth") ||
ChromeUtils.camouGetInt("window.innerHeight"))
ChromeUtils.camouGetInt("window.outerWidth") ||
ChromeUtils.camouGetInt("window.outerHeight") ||
ChromeUtils.camouGetInt("window.innerWidth") ||
ChromeUtils.camouGetInt("window.innerHeight")
) {
return;
}
Expand Down
25 changes: 21 additions & 4 deletions additions/juggler/protocol/PageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,17 @@ class PageHandler {
}

this._isDragging = false;
this._lastMousePosition = { x: 0, y: 0 };
this._lastTrackedPos = { x: 0, y: 0 };

// Camoufox: set a random default cursor position
let random_val = (max_val) => Math.floor(Math.random() * max_val);

// Try to fetch the viewport size
this._defaultCursorPos = {
x: random_val(this._pageTarget._viewportSize.width),
y: random_val(this._pageTarget._viewportSize.height),
};
this._lastMousePosition = { ...this._defaultCursorPos };
this._lastTrackedPos = { ...this._defaultCursorPos };

this._reportedFrameIds = new Set();
this._networkEventsForUnreportedFrameIds = new Map();
Expand Down Expand Up @@ -423,6 +432,14 @@ class PageHandler {
});
unsubscribe();

if (ChromeUtils.camouGetBool('memorysaver', false)) {
ChromeUtils.camouDebug('Clearing all memory...');
Services.obs.notifyObservers(null, "child-gc-request");
Cu.forceGC();
Services.obs.notifyObservers(null, "child-cc-request");
Cu.forceCC();
}

return {
navigationId: sameDocumentNavigation ? null : navigationId,
};
Expand Down Expand Up @@ -558,8 +575,8 @@ class PageHandler {
// NOTE: since this won't go inside the renderer, there's no need to wait for ACK.
win.windowUtils.sendMouseEvent(
'mousemove',
0 /* x */,
0 /* y */,
this._defaultCursorPos.x,
this._defaultCursorPos.y,
button,
clickCount,
modifiers,
Expand Down
Loading

0 comments on commit dc3c0bd

Please sign in to comment.