fix: remove electron's default user-agent keep browser user agent (#356)

This commit is contained in:
Kurisu 2024-09-12 00:39:48 +08:00 committed by GitHub
parent 961a75cd46
commit adb39bcc05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 0 deletions

View File

@ -53,6 +53,17 @@ function bootsharp() {
registerUpdater()
//remove Electron, Follow from user agent
session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => {
let userAgent = details.requestHeaders["User-Agent"]
if (userAgent) {
userAgent = userAgent.replace(/\s?Electron\/[\d.]+/, "")
userAgent = userAgent.replace(/\s?Follow\/[\d.a-zA-Z-]+/, "")
}
details.requestHeaders["User-Agent"] = userAgent
callback({ cancel: false, requestHeaders: details.requestHeaders })
})
app.on("activate", () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.