File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
packages/electron-chrome-web-store/src/renderer Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff 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+
6479function 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 )
You can’t perform that action at this time.
0 commit comments