Bug 1522755 - Ship eBay Scroll Anchoring intervention to Fennec. r=rhelmer a=lizzard
authorDennis Schubert <dschubert@mozilla.com>
Tue, 29 Jan 2019 17:36:56 +0000
changeset 515640 97295735ed424b3a791e98cae8a34e48ad14a727
parent 515639 a7206b7354fbdfba4c7f5b0d6f3909bee7f1ab36
child 515641 1a27e2f35d33bd014903cfa1f0a0c09fd54f3793
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrhelmer, lizzard
bugs1522755
milestone66.0
Bug 1522755 - Ship eBay Scroll Anchoring intervention to Fennec. r=rhelmer a=lizzard Differential Revision: https://phabricator.services.mozilla.com/D17600
mobile/android/extensions/webcompat/injections.js
mobile/android/extensions/webcompat/injections/js/bug1522755-ebay-scroll-anchoring.js
mobile/android/extensions/webcompat/manifest.json
mobile/android/extensions/webcompat/moz.build
--- a/mobile/android/extensions/webcompat/injections.js
+++ b/mobile/android/extensions/webcompat/injections.js
@@ -37,17 +37,30 @@ const contentScripts = {
     },
     {
       matches: ["*://portalminasnet.com/*"],
       js: [{file: "injections/js/bug1482066-portalminasnet.com-window.sidebar-shim.js"}],
       runAt: "document_start",
       allFrames: true,
     },
   ],
-  android: [],
+  android: [
+    {
+      matches: [
+        "*://*.ebay.at/*", "*://*.ebay.be/*", "*://*.ebay.ca/*", "*://*.ebay.ch/*",
+        "*://*.ebay.cn/*", "*://*.ebay.co.th/*", "*://*.ebay.co.uk/*", "*://*.ebay.com.au/*",
+        "*://*.ebay.com.hk/*", "*://*.ebay.com.my/*", "*://*.ebay.com.sg/*", "*://*.ebay.com.tw/*",
+        "*://*.ebay.com/*", "*://*.ebay.de/*", "*://*.ebay.es/*", "*://*.ebay.fr/*",
+        "*://*.ebay.ie/*", "*://*.ebay.in/*", "*://*.ebay.it/*", "*://*.ebay.nl/*",
+        "*://*.ebay.ph/*", "*://*.ebay.pl/*", "*://*.ebay.vn/*",
+      ],
+      js: [{file: "injections/js/bug1522755-ebay-scroll-anchoring.js"}],
+      runAt: "document_idle",
+    },
+  ],
 };
 
 /* globals browser */
 
 let port = browser.runtime.connect();
 let registeredContentScripts = [];
 
 async function registerContentScripts() {
new file mode 100644
--- /dev/null
+++ b/mobile/android/extensions/webcompat/injections/js/bug1522755-ebay-scroll-anchoring.js
@@ -0,0 +1,34 @@
+"use strict";
+
+/**
+ * ebay.com - Ebay jumps to the top once you scroll to the bottom on a mobile device
+ * Bug #1522755 - https://bugzilla.mozilla.org/show_bug.cgi?id=1522755
+ *
+ * If scroll anchoring is enabled, scrolling all the way to the bottom causes the
+ * site to scroll back up about half the page. See the bug linked above for a
+ * detailed explanation.
+ * Overriding the window.infinity.Page.prototype.hasVacancy with a version that
+ * uses a cached clientHeight resolves this issue.
+ *
+ * NOTE: This script runs at document_idle, and this is important in order for us
+ * to be able to override the method we want to override.
+ */
+
+/* globals exportFunction */
+
+if (window.wrappedJSObject.infinity && window.wrappedJSObject.infinity.Page) {
+  console.info("window.infinity.Page.prototype.hasVacancy has been overriden for compatibility reasons. See https://bugzilla.mozilla.org/show_bug.cgi?id=1520666 for details.");
+
+  // Assign the current clientHeight initially, then only update the global
+  // variable on a resize event.
+  window.mozCompatCachedClientHeight = document.documentElement.clientHeight;
+  window.wrappedJSObject.addEventListener("resize", (exportFunction(function() {
+    window.mozCompatCachedClientHeight = document.documentElement.clientHeight;
+  }, window)));
+
+  // Replace the original window.infinity.Page.prototype.hasVacancy method with
+  // a copied implementation using our cached client height.
+  window.wrappedJSObject.infinity.Page.prototype.hasVacancy = (exportFunction(function() {
+    return this.height < window.mozCompatCachedClientHeight * 3;
+  }, window));
+}
--- a/mobile/android/extensions/webcompat/manifest.json
+++ b/mobile/android/extensions/webcompat/manifest.json
@@ -1,13 +1,13 @@
 {
   "manifest_version": 2,
   "name": "Web Compat",
   "description": "Urgent post-release fixes for web compatibility.",
-  "version": "3.0.0",
+  "version": "3.0.1",
 
   "applications": {
     "gecko": {
       "id": "webcompat@mozilla.org",
       "strict_min_version": "59.0b5"
     }
   },
 
--- a/mobile/android/extensions/webcompat/moz.build
+++ b/mobile/android/extensions/webcompat/moz.build
@@ -20,13 +20,14 @@ FINAL_TARGET_FILES.features['webcompat@m
 ]
 
 FINAL_TARGET_FILES.features['webcompat@mozilla.org']['injections']['js'] += [
   'injections/js/bug0000000-dummy-js-injection.js',
   'injections/js/bug1452707-window.controllers-shim-ib.absa.co.za.js',
   'injections/js/bug1457335-histography.io-ua-change.js',
   'injections/js/bug1472075-bankofamerica.com-ua-change.js',
   'injections/js/bug1472081-election.gov.np-window.sidebar-shim.js',
-  'injections/js/bug1482066-portalminasnet.com-window.sidebar-shim.js'
+  'injections/js/bug1482066-portalminasnet.com-window.sidebar-shim.js',
+  'injections/js/bug1522755-ebay-scroll-anchoring.js'
 ]
 
 with Files('**'):
   BUG_COMPONENT = ('Web Compatibility Tools', 'Go Faster')