From 58927524e3cc16cc4f59bca09a6c352cec1a16ac Mon Sep 17 00:00:00 2001 From: PalmerAL Date: Sun, 15 Aug 2021 13:37:16 -0500 Subject: [PATCH] implement partial UA client hints support for gmail --- js/preload/siteUnbreak.js | 23 +++++++++++++++++++++++ main/UASwitcher.js | 5 +++++ 2 files changed, 28 insertions(+) diff --git a/js/preload/siteUnbreak.js b/js/preload/siteUnbreak.js index 7059ffa98..93484a2bb 100644 --- a/js/preload/siteUnbreak.js +++ b/js/preload/siteUnbreak.js @@ -96,6 +96,29 @@ if (window.location.hostname === 'calendar.google.com') { `) } +/* Gmail - required for loading standard version (otherwise redirects to basic HTML) */ + +if (window.location.hostname === 'mail.google.com') { + const chromiumVersion = process.versions.chrome.split('.')[0] + scriptsToRun.push(` + (function() { + const simulatedUAData = { + brands: [ + {brand: "Chromium", version: "${chromiumVersion}"}, + {brand: "Not A;Brand", version: "99"} + ], + mobile: false, + getHighEntropyValues: function() { + console.warn('getHighEntropyValues is unimplemented', arguments) + return null + } + } + + Object.defineProperty(navigator, 'userAgentData', {get: () => simulatedUAData}) + })() + `) +} + if (scriptsToRun.length > 0) { setTimeout(function () { electron.webFrame.executeJavaScript(scriptsToRun.join(';')) diff --git a/main/UASwitcher.js b/main/UASwitcher.js index 40fb63011..8d007cb9e 100644 --- a/main/UASwitcher.js +++ b/main/UASwitcher.js @@ -26,6 +26,11 @@ function enableGoogleUASwitcher (ses) { details.requestHeaders['User-Agent'] = newUserAgent + ' Edg/' + process.versions.chrome } } + + const chromiumVersion = process.versions.chrome.split('.')[0] + details.requestHeaders['SEC-CH-UA'] = `"Chromium";v="${chromiumVersion}", " Not A;Brand";v="99"` + details.requestHeaders['SEC-CH-UA-MOBILE'] = '?0' + callback({ cancel: false, requestHeaders: details.requestHeaders }) }) }