c8eef4a1e85bcfd8b41e87e287cbf15f09fc357a
jcasper
  Sun Aug 16 22:19:22 2020 -0700
Replacing beforeUnload synchronous updates (blocked by Chrome) with async updates.
Also fixing the suggestion box, so following a suggestion turns on the track and highlights the item.
refs #25017, #25703

diff --git src/hg/js/ajax.js src/hg/js/ajax.js
index b9ec22b..b448d00 100644
--- src/hg/js/ajax.js
+++ src/hg/js/ajax.js
@@ -181,41 +181,56 @@
     var data = "submit=1&noDisplay=1&hgsid=" + hgsid;
     var track = getTrack();
     if (track && track.length > 0)
         data = data + "&g=" + track;
     for(var ix=0; ix<names.length; ix++) {
         data = data + "&" + encodeURIComponent(names[ix]) + "=" + encodeURIComponent(values[ix]);
     }
     var type;
     // We prefer GETs so we can analyze logs, but use POSTs if data is longer than a
     // (conservatively small)  maximum length to avoid problems on older versions of IE.
     if ((loc.length + data.length) > 2000) {
         type = "POST";
     } else {
         type = "GET";
     }
+
+    if (typeof bowser === 'undefined') {
+        bowserScript = document.createElement('script');
+        bowserScript.setAttribute('src', 'https://cdnjs.cloudflare.com/ajax/libs/bowser/1.6.1/bowser.min.js');
+        document.head.appendChild(bowserScript);
+    }
+
+    if (!async || (typeof bowser !== 'undefined' && bowser.msie)) {
+        // XmlHttpRequest is used for all synchronous updates and for async updates in IE,
+        // because IE doesn't support sendBeacon.  If access to bowser is blocked, the default
+        // is to assume the browser is not IE.
         $.ajax({
                    type: type,
                    async: async,
                    url: loc,
                    data: data,
                    trueSuccess: function () {},
                    success: catchErrorOrDispatch,
                    error: errFunc,
                    cache: false
                });
     }
+    else {
+        navigator.sendBeacon(loc, data);
+    }
+}
 
 function setCartVar(name, value, errFunc, async)
 {
 // Asynchronously set a cart variable.
     setCartVars( [ name ], [ value ], errFunc, async );
 }
 
 function setVarsFromHash(varHash, errFunc, async)
 {
 // Set all vars in a var hash
 // If obj is undefined then obj is document!
     var names = [];
     var values = [];
     for (var aVar in varHash) {
         names.push(aVar);