Skip to content

Commit

Permalink
use Edge UA for google sign-in (#1119)
Browse files Browse the repository at this point in the history
  • Loading branch information
PalmerAL authored Jul 10, 2020
1 parent 2fdee3d commit 936a1ea
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions main/UASwitcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,36 @@
see https://github.com/minbrowser/min/issues/657 for more information */

let defaultUserAgent = app.userAgentFallback
let hasCustomUserAgent = false
let newUserAgent

if (settings.get('customUserAgent')) {
newUserAgent = settings.get('customUserAgent')
hasCustomUserAgent = true
} else {
newUserAgent = defaultUserAgent.replace(/Min\/\S+\s/, '').replace(/Electron\/\S+\s/, '')
}
app.userAgentFallback = newUserAgent

/*
Google blocks signin in some cases unless a custom UA is used
see https://github.com/minbrowser/min/issues/868
*/
function enableGoogleUASwitcher (ses) {
ses.webRequest.onBeforeSendHeaders((details, callback) => {
if (!hasCustomUserAgent && details.url.includes('accounts.google.com')) {
const url = new URL(details.url)

if (url.hostname === 'accounts.google.com') {
details.requestHeaders['User-Agent'] = newUserAgent + ' Edg/' + process.versions.chrome
}
}
callback({ cancel: false, requestHeaders: details.requestHeaders })
})
}

app.once('ready', function () {
enableGoogleUASwitcher(session.defaultSession)
})

app.on('session-created', enableGoogleUASwitcher)

0 comments on commit 936a1ea

Please sign in to comment.