Every time an api call is made i get the error:
Refused to set unsafe header "User-Agent"
I'm using the API package in an electron app.
x in one of the [ ])x in each of the [ ])Filling out the following details about bugs will help us solve your issue sooner.
Select all that apply:
@slack/web-api -> not sure about the others@slack/events-api@slack/interactive-messages@slack/rtm-api@slack/webhooksThe API call is done properly, but since the Slack APIs try to change the user agent (probably to track node version and os version), this throw an error in chrome, since it's not allowing this.
This lead to errors being logged in console for every call. The call itself is not actually compromised, but the console can be flooded with errors.
Error are logged by chrome. I would expect these error not to be logged, being catchable, or having the possibility to prevent the user agent change.
Creating the client in this way:
new SlackWebClient(data.authed_user.access_token, { headers: { 'User-Agent': undefined } })
i.e. forcing it to not have a user-agent is not fixing the problem (apparently the library is still trying to set it as "undefined".
Backtrace:
/Users/oltreseba/project/node_modules/axios/lib/adapters/xhr.js:126 Refused to set unsafe header "User-Agent"
setRequestHeader @ /Users/oltreseba/project/node_modules/axios/lib/adapters/xhr.js:126
forEach @ /Users/oltreseba/project/node_modules/axios/lib/utils.js:238
dispatchXhrRequest @ /Users/oltreseba/project/node_modules/axios/lib/adapters/xhr.js:120
xhrAdapter @ /Users/oltreseba/project/node_modules/axios/lib/adapters/xhr.js:12
dispatchRequest @ /Users/oltreseba/project/node_modules/axios/lib/core/dispatchRequest.js:52
Promise.then (async)
request @ /Users/oltreseba/project/node_modules/axios/lib/core/Axios.js:61
Axios.<computed> @ /Users/oltreseba/project/node_modules/axios/lib/core/Axios.js:86
wrap @ /Users/oltreseba/project/node_modules/axios/lib/helpers/bind.js:9
(anonymous) @ /Users/oltreseba/project/node_modules/@slack/web-api/dist/WebClient.js:570
run @ /Users/oltreseba/project/node_modules/p-queue/index.js:99
(anonymous) @ /Users/oltreseba/project/node_modules/p-queue/index.js:116
add @ /Users/oltreseba/project/node_modules/p-queue/index.js:94
task @ /Users/oltreseba/project/node_modules/@slack/web-api/dist/WebClient.js:567
(anonymous) @ /Users/oltreseba/project/node_modules/p-retry/index.js:41
RetryOperation.attempt @ /Users/oltreseba/project/node_modules/retry/lib/retry_operation.js:112
(anonymous) @ /Users/oltreseba/project/node_modules/p-retry/index.js:39
pRetry @ /Users/oltreseba/project/node_modules/p-retry/index.js:30
makeRequest @ /Users/oltreseba/project/node_modules/@slack/web-api/dist/WebClient.js:614
apiCall @ /Users/oltreseba/project/node_modules/@slack/web-api/dist/WebClient.js:458
Same here. Every single API-Call is generating an "Unsafe Header" error.
same case me too, and I escaped this case.
// typescript
import * as slack from "@slack/web-api";
const client= new slack.WebClient("TOKEN");
delete client["axios"].defaults.headers["User-Agent"];
Most helpful comment
same case me too, and I escaped this case.