diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index 6278f22cc996..83865569014c 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -1338,12 +1338,8 @@ Tab.prototype = { this._viewport.x = Math.round(this._viewport.x * this._viewport.zoom); this._viewport.y = Math.round(this._viewport.y * this._viewport.zoom); - /* - * Don't alter the page size until we hit DOMContentLoaded, because this causes the page size - * to jump around wildly during page load. - */ let doc = this.browser.contentDocument; - if (doc != null && doc.readyState === 'complete') { + if (doc != null) { let pageWidth = this._viewport.width, pageHeight = this._viewport.height; let body = doc.body || { scrollWidth: pageWidth, scrollHeight: pageHeight }; let html = doc.documentElement || { scrollWidth: pageWidth, scrollHeight: pageHeight }; @@ -1351,8 +1347,18 @@ Tab.prototype = { pageHeight = Math.max(body.scrollHeight, html.scrollHeight); /* Transform the page width and height based on the zoom factor. */ - this._viewport.pageWidth = Math.round(pageWidth * this._viewport.zoom); - this._viewport.pageHeight = Math.round(pageHeight * this._viewport.zoom); + pageWidth = Math.round(pageWidth * this._viewport.zoom); + pageHeight = Math.round(pageHeight * this._viewport.zoom); + + /* + * Avoid sending page sizes of less than screen size before we hit DOMContentLoaded, because + * this causes the page size to jump around wildly during page load. After the page is loaded, + * send updates regardless of page size; we'll zoom to fit the content as needed. + */ + if (doc.readyState === 'complete' || (pageWidth >= gScreenWidth && pageHeight >= gScreenHeight)) { + this._viewport.pageWidth = pageWidth; + this._viewport.pageHeight = pageHeight; + } } return this._viewport;