Skip to content

Commit c90947f

Browse files
committed
Disabled setting 'User-Agent' in browser environments by default
refs https://github.com/TryGhost/Toolbox/issues/348 refs https://github.com/TryGhost/Toolbox/issues/301 closes #426 refs https://bugs.chromium.org/p/chromium/issues/detail?id=571722 - When Content API SDK is used in Chrome browser the requests are throwing "Refused to set unsafe header "User-Agent" errors. This is a bug in chrome due to historical reasons - the "User-Agent" header used to be on a "forbidden header names" list and still is in chrome. - In case the client needs to send the User-Agent header in Firefox for example the SDK can be configured with `userAgent: true` parameter
1 parent 081a19a commit c90947f

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

packages/content-api/lib/content-api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import axios from 'axios';
22
import packageInfo from '../package.json';
33

4+
// @NOTE: this value is dynamically replaced based on browser/node environment
45
const USER_AGENT_DEFAULT = true;
56

67
const packageVersion = packageInfo.version;

packages/content-api/rollup.config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ export default [
6060
exclude: ['node_modules/**', '../../node_modules/**']
6161
}),
6262
replace({
63-
'process.env.NODE_ENV': `"${process.env.NODE_ENV}"`
63+
'process.env.NODE_ENV': `"${process.env.NODE_ENV}"`,
64+
'USER_AGENT_DEFAULT = true': `USER_AGENT_DEFAULT = false`
6465
})
6566
]
6667
},
@@ -97,7 +98,8 @@ export default [
9798
exclude: ['node_modules/**', '../../node_modules/**']
9899
}),
99100
replace({
100-
'process.env.NODE_ENV': `"${process.env.NODE_ENV}"`
101+
'process.env.NODE_ENV': `"${process.env.NODE_ENV}"`,
102+
'USER_AGENT_DEFAULT = true': `USER_AGENT_DEFAULT = false`
101103
}),
102104
terser()
103105
]

0 commit comments

Comments
 (0)