diff --git a/app/app-main.js b/app/app-main.js index 6bcb7622..211d004a 100644 --- a/app/app-main.js +++ b/app/app-main.js @@ -1,13 +1,12 @@ import { EventEmitter } from 'events'; import { parse } from 'url'; -import { app, webContents } from 'electron'; +import { app, session, webContents } from 'electron'; import log from 'electron-log'; import services from './services/servicesManager'; import { observer } from './services/lib/helpers'; import { handleError } from './services/api/helpers'; import { start } from './webui/webUIHandler'; - -require('./session'); +import { enhanceSession } from './session'; export default class BrowserXAppMain extends EventEmitter { init() { @@ -18,10 +17,12 @@ export default class BrowserXAppMain extends EventEmitter { initAppLifeCycle() { app.on('ready', async () => { + enhanceSession(session.defaultSession); // can register a onOpen function that should return a promise if (typeof this.onOpen === 'function') { await this.onOpen(); } + }); } diff --git a/app/main.ts b/app/main.ts index ac803dc0..4b598cc2 100644 --- a/app/main.ts +++ b/app/main.ts @@ -92,8 +92,6 @@ const loadCliWindow = async (command: string) => { const initWorker = () => { app.on('ready', () => { - enhanceSession(session.defaultSession); - loadWorker(); if (module.hot) { diff --git a/app/services/services/auto-updater/lib.ts b/app/services/services/auto-updater/lib.ts index dbb4afe5..2de908a2 100644 --- a/app/services/services/auto-updater/lib.ts +++ b/app/services/services/auto-updater/lib.ts @@ -2,4 +2,8 @@ import { isPackaged } from '../../../utils/env'; import AutoUpdaterMock from './AutoUpdaterMock'; import { autoUpdater as autoUpdaterProd } from 'electron-updater'; -export const autoUpdater = !isPackaged ? new AutoUpdaterMock() : autoUpdaterProd; +if (isPackaged) { + autoUpdaterProd.allowPrerelease = false; +} + +export const autoUpdater = isPackaged ? autoUpdaterProd : new AutoUpdaterMock(); diff --git a/app/session.ts b/app/session.ts index c6a8d551..3ecaf328 100644 --- a/app/session.ts +++ b/app/session.ts @@ -2,24 +2,7 @@ import { Session, OnBeforeSendHeadersListenerDetails, OnHeadersReceivedListenerD HeadersReceivedResponse, BeforeSendResponse } from 'electron'; import enhanceWebRequest from 'electron-better-web-request'; -const defaultUserAgent = [ - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)', - 'AppleWebKit/537.36 (KHTML, like Gecko)', - 'Chrome/112.0.0.0', - 'Safari/537.36', -].join(' '); - -export const getUserAgentForApp = (url: string, currentUserAgent: string): string => { - - if (url.startsWith('file://') || url.startsWith('http://localhost')) { - return currentUserAgent; - } - else if (url.startsWith('https://accounts.google.com')) { - return 'Chrome/87.0.4280.141'; - } - - return defaultUserAgent; -}; +const defaultUserAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.5735.289 Safari/537.36'; const getHeaderName = (headerName: string, headers?: Record): string | undefined => { if (headers) { @@ -56,11 +39,12 @@ export const getRefererForApp = (referer: string): string => { export const enhanceSession = (session: Session) => { enhanceWebRequest(session); + session.setUserAgent(defaultUserAgent); + session.webRequest.onBeforeSendHeaders( (details: OnBeforeSendHeadersListenerDetails, callback: (beforeSendResponse: BeforeSendResponse) => void) => { - details.requestHeaders['User-Agent'] = getUserAgentForApp(details.url, session.getUserAgent()); details.referrer = getRefererForApp(details.referrer); - details.requestHeaders.Referer = details.referrer; + details.requestHeaders['Referer'] = details.referrer; callback({ cancel: false, @@ -68,20 +52,4 @@ export const enhanceSession = (session: Session) => { }); } ); - - // session.webRequest.onHeadersReceived( - // (details: OnHeadersReceivedListenerDetails, callback: (headersReceivedResponse: HeadersReceivedResponse) => void) => { - - // let headers = details.responseHeaders; - // if (getHeader('X-Frame-Options', headers)) { - // headers = setHeader('X-Frame-Options', 'SAMEORIGIN', headers); - // } - - // callback({ - // cancel: false, - // responseHeaders: headers, - // statusLine: details.statusLine - // }); - // } - // ); } \ No newline at end of file diff --git a/manifests/definitions/114.json b/manifests/definitions/114.json index 061d9d23..69eabee4 100644 --- a/manifests/definitions/114.json +++ b/manifests/definitions/114.json @@ -21,6 +21,5 @@ "instance_wording": "account", "instance_label_tpl": "{{email}}", "start_url_tpl": "https://inbox.google.com/{{#if moreThanOneIdentity}}u/{{userIdentity.profileData.email}}{{/if}}" - }, - "bx_override_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36 Edge/80.0.361.62" + } } diff --git a/manifests/definitions/122.json b/manifests/definitions/122.json index f68e0fe3..a35aa82b 100644 --- a/manifests/definitions/122.json +++ b/manifests/definitions/122.json @@ -10,7 +10,6 @@ ], "theme_color": "#25D366", "scope": "https://web.whatsapp.com", - "bx_override_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36", "bx_keep_always_loaded": true, "bx_legacy_service_id": "whatsapp", "recommendedPosition": "4" diff --git a/manifests/definitions/131.json b/manifests/definitions/131.json index 6d10a78d..4513d0dc 100644 --- a/manifests/definitions/131.json +++ b/manifests/definitions/131.json @@ -11,6 +11,5 @@ "theme_color": "#5559AE", "scope": "https://teams.live.com", "bx_legacy_service_id": "microsoft-teams", - "bx_override_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36", "recommendedPosition": "25" } diff --git a/manifests/definitions/14.json b/manifests/definitions/14.json index 1a892a8e..894b161b 100644 --- a/manifests/definitions/14.json +++ b/manifests/definitions/14.json @@ -10,7 +10,6 @@ ], "theme_color": "#e75a4d", "scope": "https://mail.google.com", - "bx_override_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36 Edge/80.0.361.62", "bx_keep_always_loaded": true, "bx_single_page": true, "bx_legacy_service_id": "gmail", diff --git a/manifests/definitions/156.json b/manifests/definitions/156.json index e5147090..0538c5d5 100644 --- a/manifests/definitions/156.json +++ b/manifests/definitions/156.json @@ -20,6 +20,5 @@ "instance_label_tpl": "{{email}}", "start_url_tpl": "https://keep.google.com/{{#if moreThanOneIdentity}}u/{{userIdentity.profileData.email}}{{/if}}" }, - "bx_override_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36 Edge/80.0.361.62", "recommendedPosition": "14" } diff --git a/manifests/definitions/16.json b/manifests/definitions/16.json index d77b2132..d68b5cf6 100644 --- a/manifests/definitions/16.json +++ b/manifests/definitions/16.json @@ -25,6 +25,5 @@ "start_url_tpl": "https://accounts.google.com/AddSession?passive=true&Email={{userIdentity.profileData.email}}&continue=https://drive.google.com/drive/{{#if moreThanOneIdentity}}u/{{userIdentity.profileData.email}}{{/if}}", "new_page_url_tpl": "https://drive.google.com/drive/{{#if moreThanOneIdentity}}u/{{userIdentity.profileData.email}}{{/if}}" }, - "bx_override_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36 Edge/80.0.361.62", "recommendedPosition": "3" } diff --git a/manifests/definitions/18.json b/manifests/definitions/18.json index eaf6c2e4..49804c8b 100644 --- a/manifests/definitions/18.json +++ b/manifests/definitions/18.json @@ -26,6 +26,5 @@ "instance_label_tpl": "{{email}}", "start_url_tpl": "https://accounts.google.com/AddSession?passive=true&Email={{userIdentity.profileData.email}}&continue=https://calendar.google.com/calendar/{{#if moreThanOneIdentity}}b/{{userIdentity.profileData.email}}{{/if}}" }, - "bx_override_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36 Edge/80.0.361.62", "recommendedPosition": "2" } diff --git a/manifests/definitions/2165.json b/manifests/definitions/2165.json index aa326f37..6cef7119 100644 --- a/manifests/definitions/2165.json +++ b/manifests/definitions/2165.json @@ -12,6 +12,5 @@ } ], "theme_color": "#fe362a", - "bx_override_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36 Edge/80.0.361.62", "recommendedPosition": "16" } diff --git a/manifests/definitions/254.json b/manifests/definitions/254.json index ea0d8525..02ca5e12 100644 --- a/manifests/definitions/254.json +++ b/manifests/definitions/254.json @@ -11,7 +11,6 @@ "theme_color": "#C75B12", "scope": "https://www.office.com", "bx_legacy_service_id": "office-365", - "bx_override_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36", "extended_scopes": [ "https://office.live.com", "https://www.onenote.com", diff --git a/manifests/definitions/272.json b/manifests/definitions/272.json index f42d2ba2..f6f90950 100644 --- a/manifests/definitions/272.json +++ b/manifests/definitions/272.json @@ -10,6 +10,5 @@ ], "theme_color": "#DC4B3E", "scope": "https://maps.google.com", - "bx_legacy_service_id": "googlemaps", - "bx_override_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36 Edge/80.0.361.62" + "bx_legacy_service_id": "googlemaps" } diff --git a/manifests/definitions/284.json b/manifests/definitions/284.json index 1a74c5e5..c5a8a451 100644 --- a/manifests/definitions/284.json +++ b/manifests/definitions/284.json @@ -10,6 +10,5 @@ ], "theme_color": "#2494CA", "scope": "https://workflowy.com", - "bx_legacy_service_id": "workflowy", - "bx_override_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36" + "bx_legacy_service_id": "workflowy" } diff --git a/manifests/definitions/403.json b/manifests/definitions/403.json index 5daaeb31..736fea51 100644 --- a/manifests/definitions/403.json +++ b/manifests/definitions/403.json @@ -14,6 +14,5 @@ "theme_color": "#4c8cf4", "scope": "https://translate.google.com", "bx_legacy_service_id": "google-translate", - "bx_override_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36 Edge/80.0.361.62", "recommendedPosition": "26" } diff --git a/manifests/definitions/517.json b/manifests/definitions/517.json index 664bca56..af82c903 100644 --- a/manifests/definitions/517.json +++ b/manifests/definitions/517.json @@ -25,6 +25,5 @@ "instance_wording": "account", "instance_label_tpl": "{{email}}", "start_url_tpl": "https://accounts.google.com/AddSession?passive=true&Email={{userIdentity.profileData.email}}&continue=https://chat.google.com/chat/u/{{userIdentity.profileData.email}}" - }, - "bx_override_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36" + } } diff --git a/manifests/definitions/8563.json b/manifests/definitions/8563.json index 3aa848c4..8c9f4aa1 100644 --- a/manifests/definitions/8563.json +++ b/manifests/definitions/8563.json @@ -9,6 +9,5 @@ } ], "theme_color": "#bcf", - "scope": "https://cs.chromium.org", - "bx_override_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36 Edge/80.0.361.62" + "scope": "https://cs.chromium.org" }