From 3bbab525c6c7ebcb2ca8cd1ff0d7b59495f945ea Mon Sep 17 00:00:00 2001 From: TC Date: Sun, 12 Apr 2020 21:54:35 +0200 Subject: [PATCH] Only set user-agent on accounts.google.com (affects preload scripts otherwise) --- index.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index a3219f2749..ebab1c37f7 100644 --- a/index.js +++ b/index.js @@ -60,12 +60,7 @@ function createMainWindow() { win.maximize(); } - // Force user-agent "Firefox Windows" for Google OAuth to work - // From https://github.com/firebase/firebase-js-sdk/issues/2478#issuecomment-571356751 - const userAgent = - "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:70.0) Gecko/20100101 Firefox/70.0"; - - win.webContents.loadURL(store.get("url"), { userAgent }); + win.webContents.loadURL(store.get("url")); win.on("closed", onClosed); injectCSS(win.webContents, path.join(__dirname, "youtube-music.css")); @@ -99,6 +94,21 @@ function createMainWindow() { } }); + win.webContents.on("will-navigate", (_, url) => { + if (url.startsWith("https://accounts.google.com")) { + // Force user-agent "Firefox Windows" for Google OAuth to work + // From https://github.com/firebase/firebase-js-sdk/issues/2478#issuecomment-571356751 + // Only set on accounts.google.com, otherwise querySelectors in preload scripts fail (?) + const userAgent = + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:70.0) Gecko/20100101 Firefox/70.0"; + + win.webContents.session.webRequest.onBeforeSendHeaders((details, cb) => { + details.requestHeaders["User-Agent"] = userAgent; + cb({ requestHeaders: details.requestHeaders }); + }); + } + }); + win.webContents.on( "new-window", (e, url, frameName, disposition, options) => {