Skip to content

Commit

Permalink
Only set user-agent on accounts.google.com (affects preload scripts o…
Browse files Browse the repository at this point in the history
…therwise)
  • Loading branch information
th-ch committed Apr 12, 2020
1 parent d42b7bc commit 3bbab52
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 3bbab52

Please sign in to comment.