Skip to content

Commit

Permalink
User-Agent Fix for #441 (#450)
Browse files Browse the repository at this point in the history
Modified how the user agent is set when sending headers. There were two issues that I was able to identify.

First, the Google sign-in page sends requests to the youtube.com domain sometimes, so the existing replacement effect was not always firing. Adding a url entry for this domain fixes this problem.

Second, Google sometimes doesn't like the hard-coded user agent this project was previously providing. I have no idea why -- this Electron/user agent/Google problem has been ongoing for years. I've solved this problem this time by instead taking the user agent Electron would have passed by itself and stripping out only the Electron-specific component.

I don't know how long this fix will last, since Google seems intent on being opaque about how they determine if a browser is secure or not. Fingers crossed.

Co-authored-by: Doc Islands <[email protected]>
  • Loading branch information
drislands and bojjenclon authored Jun 8, 2024
1 parent f4ab33d commit 528f80c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,27 @@ if (gotTheLock) {
mainWindow.show();
}

// set user agent to potentially make google fi work
const userAgent =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/117.0";

// Fix the user agent -- Google sends auth requests to YouTube as well, for some reason
mainWindow.webContents.session.webRequest.onBeforeSendHeaders(
{
urls: ["https://accounts.google.com/*"],
urls: ["https://*.google.com/*", "https://*.youtube.com/*"],
},
({ requestHeaders }, callback) =>
callback({
requestHeaders: { ...requestHeaders, "User-Agent": userAgent },
requestHeaders: {
...requestHeaders,
// Specifically, we are ONLY removing the Electron portion of the agent
// Found via https://old.reddit.com/r/electronjs/comments/eiy2sf/google_blocking_log_in_from_electron_apps/fcvuwd9/
// Referenced at this link https://github.com/firebase/firebase-js-sdk/issues/2478#issuecomment-571773318
"User-Agent": mainWindow.webContents.userAgent.replace(
"Electron/" + process.versions.electron,
""
),
},
})
);

mainWindow.loadURL("https://messages.google.com/web/");
mainWindow.webContents.loadURL("https://messages.google.com/web/");

trayManager.startIfEnabled();
settings.showIconsInRecentConversationTrayEnabled.subscribe(() =>
Expand Down

0 comments on commit 528f80c

Please sign in to comment.