Skip to content

Commit a8dea57

Browse files
committed
fix(Service): Fix issue with user agent override in service workers
1 parent 922f861 commit a8dea57

File tree

4 files changed

+55
-5
lines changed

4 files changed

+55
-5
lines changed

package-lock.json

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"hex-to-rgba": "1.0.2",
5858
"jsonwebtoken": "8.5.1",
5959
"lodash": "^4.17.4",
60+
"macos-version": "5.2.0",
6061
"marked": "0.6.1",
6162
"mdi": "^1.9.33",
6263
"mime-types": "2.1.21",

src/electron/userAgent.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
import os from 'os';
3+
import macosVersion from 'macos-version';
4+
import { isMac, isWindows } from '../environment';
5+
6+
function macOS() {
7+
const version = macosVersion();
8+
9+
return `Macintosh; Intel Mac OS X ${version.replace('.', '_')}`;
10+
}
11+
12+
function windows() {
13+
const version = os.release();
14+
const [majorVersion, minorVersion] = version.split('.');
15+
return `Windows NT ${majorVersion}.${minorVersion}; Win64; x64`;
16+
}
17+
18+
function linux() {
19+
return 'X11; Ubuntu; Linux x86_64';
20+
}
21+
22+
export default function userAgent() {
23+
let platformString = '';
24+
25+
if (isMac) {
26+
platformString = macOS();
27+
} else if (isWindows) {
28+
platformString = windows();
29+
} else {
30+
platformString = linux();
31+
}
32+
33+
// TODO: Update AppleWebKit and Safari version after electron update
34+
return `Mozilla/5.0 (${platformString}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${process.versions.chrome} Safari/537.36`;
35+
}

src/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ if (isDevMode) {
2222
app.setPath('userData', path.join(app.getPath('appData'), 'FranzDev'));
2323
}
2424

25+
2526
/* eslint-disable import/first */
2627
import {
2728
isMac,
@@ -43,10 +44,15 @@ import {
4344
} from './config';
4445
import { asarPath } from './helpers/asar-helpers';
4546
import { isValidExternalURL } from './helpers/url-helpers';
46-
/* eslint-enable import/first */
47+
import userAgent from './electron/userAgent';
4748

49+
/* eslint-enable import/first */
4850
const debug = require('debug')('Franz:App');
4951

52+
// Globally set useragent to fix user agent override in service workers
53+
debug('Set userAgent to ', userAgent());
54+
app.userAgentFallback = userAgent();
55+
5056
// Keep a global reference of the window object, if you don't, the window will
5157
// be closed automatically when the JavaScript object is garbage collected.
5258
let mainWindow;

0 commit comments

Comments
 (0)