Skip to content

Commit 1b7d5d5

Browse files
committed
fix: 'switch to chrome' on web store
1 parent 3a7845e commit 1b7d5d5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

packages/electron-chrome-web-store/src/renderer/web-store-preload.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,21 @@ function updateBranding(appName: string) {
6161
setTimeout(update, 1000 / 60)
6262
}
6363

64+
function getUAProductVersion(userAgent: string, product: string) {
65+
const regex = new RegExp(`${product}/([\\d.]+)`)
66+
return userAgent.match(regex)?.[1]
67+
}
68+
69+
function overrideUserAgent() {
70+
const chromeVersion = getUAProductVersion(navigator.userAgent, 'Chrome') || '133.0.6920.0'
71+
const userAgent = `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion} Safari/537.36`
72+
webFrame.executeJavaScript(
73+
`(${function (userAgent: string) {
74+
Object.defineProperty(navigator, 'userAgent', { value: userAgent })
75+
}})(${JSON.stringify(userAgent)});`,
76+
)
77+
}
78+
6479
function setupChromeWebStoreApi() {
6580
let appName: string | undefined
6681

@@ -291,6 +306,7 @@ function setupChromeWebStoreApi() {
291306
electronWebstore.getFullChromeVersion()
292307

293308
// Replace branding
309+
overrideUserAgent()
294310
process.once('document-start', maybeUpdateBranding)
295311
if ('navigation' in window) {
296312
;(window.navigation as any).addEventListener('navigate', maybeUpdateBranding)

0 commit comments

Comments
 (0)