Skip to content

Commit 3bbab52

Browse files
committed
Only set user-agent on accounts.google.com (affects preload scripts otherwise)
1 parent d42b7bc commit 3bbab52

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

index.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,7 @@ function createMainWindow() {
6060
win.maximize();
6161
}
6262

63-
// Force user-agent "Firefox Windows" for Google OAuth to work
64-
// From https://github.com/firebase/firebase-js-sdk/issues/2478#issuecomment-571356751
65-
const userAgent =
66-
"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:70.0) Gecko/20100101 Firefox/70.0";
67-
68-
win.webContents.loadURL(store.get("url"), { userAgent });
63+
win.webContents.loadURL(store.get("url"));
6964
win.on("closed", onClosed);
7065

7166
injectCSS(win.webContents, path.join(__dirname, "youtube-music.css"));
@@ -99,6 +94,21 @@ function createMainWindow() {
9994
}
10095
});
10196

97+
win.webContents.on("will-navigate", (_, url) => {
98+
if (url.startsWith("https://accounts.google.com")) {
99+
// Force user-agent "Firefox Windows" for Google OAuth to work
100+
// From https://github.com/firebase/firebase-js-sdk/issues/2478#issuecomment-571356751
101+
// Only set on accounts.google.com, otherwise querySelectors in preload scripts fail (?)
102+
const userAgent =
103+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:70.0) Gecko/20100101 Firefox/70.0";
104+
105+
win.webContents.session.webRequest.onBeforeSendHeaders((details, cb) => {
106+
details.requestHeaders["User-Agent"] = userAgent;
107+
cb({ requestHeaders: details.requestHeaders });
108+
});
109+
}
110+
});
111+
102112
win.webContents.on(
103113
"new-window",
104114
(e, url, frameName, disposition, options) => {

0 commit comments

Comments
 (0)