omegafox/patches/viewport-hijacker.patch
2024-09-22 08:26:38 -05:00

62 lines
2.7 KiB
Diff

diff --git a/browser/base/content/browser-init.js b/browser/base/content/browser-init.js
index bee5309c04..d7fa2af364 100644
--- a/browser/base/content/browser-init.js
+++ b/browser/base/content/browser-init.js
@@ -72,7 +72,7 @@ var gBrowserInit = {
updateBookmarkToolbarVisibility();
// Set a sane starting width/height for all resolutions on new profiles.
- if (ChromeUtils.shouldResistFingerprinting("RoundWindowSize", null)) {
+ if (true || ChromeUtils.shouldResistFingerprinting("RoundWindowSize", null)) {
// When the fingerprinting resistance is enabled, making sure that we don't
// have a maximum window to interfere with generating rounded window dimensions.
document.documentElement.setAttribute("sizemode", "normal");
@@ -302,6 +302,48 @@ var gBrowserInit = {
)?.removeAttribute("key");
}
+ // Set default size
+ window.resizeTo(1280, 1040);
+
+ // Hijack the outer window size
+ let outerWidth, outerHeight;
+ if ((outerWidth = ChromeUtils.camouGetInt("window.outerWidth"))) {
+ document.documentElement.style.setProperty('width', outerWidth + 'px');
+ browser.style.setProperty('width', outerWidth + 'px');
+ window.resizeTo(outerWidth, window.outerHeight);
+ }
+ if ((outerHeight = ChromeUtils.camouGetInt("window.outerHeight"))) {
+ document.documentElement.style.setProperty('height', outerHeight + 'px');
+ browser.style.setProperty('height', outerHeight + 'px');
+ window.resizeTo(window.outerWidth, outerHeight);
+ }
+ browser.style.setProperty('box-sizing', 'content-box');
+
+ // Hijack the inner window size
+ let innerWidth = ChromeUtils.camouGetInt("window.innerWidth") || ChromeUtils.camouGetInt("document.body.clientWidth");
+ let innerHeight = ChromeUtils.camouGetInt("window.innerHeight") || ChromeUtils.camouGetInt("document.body.clientHeight");
+
+ if (innerWidth || innerHeight) {
+ let win_inner_style = document.createElement('style');
+ win_inner_style.innerHTML = `
+ .browserStack {
+ ${innerWidth ? `width: ${innerWidth}px !important;` : ''}
+ ${innerHeight ? `height: ${innerHeight}px !important;` : ''}
+ ${innerHeight ? `flex: unset !important;` : ''}
+ overflow: auto;
+ contain: size;
+ scrollbar-width: none;
+ }
+ `;
+ document.head.appendChild(win_inner_style);
+ }
+
+ if (innerWidth && innerHeight && !(outerWidth || outerHeight)) {
+ let stackRect = __browserStack.getBoundingClientRect();
+ let toolbarTop = stackRect.y;
+ window.resizeBy(width - innerWidth, height + toolbarTop - innerHeight);
+ }
+
this._loadHandled = true;
},