question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set own default UserAgent

See original GitHub issue

If i want to use my own user-agent on every request i am doing with node-fetch i currently have to add the header every time i use fetch. In my opinion there should be a possibility to set a global default user-agent because the user-agent is always static for the lifetime of the application (or not?) and setting it every time is a unnecessary overhead.

Something like:

fetch.setDefaultUserAgent('myApp/1.0.1 (MYSERVER; Linux) node-fetch');

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:14

github_iconTop GitHub Comments

12reactions
jimmywartingcommented, Mar 19, 2019

easies thing you could do right now is maybe to just build a own wrapper around node-fetch

// fetch.js
const fetch = require('node-fetch')

module.exports = (url, args = {}) => {
  args.headers = args.headers || {}
  args.headers['user-agent'] = 'my own'
  return fetch(url, args)
}


// main.js
const fetch = require('./fetch.js')
fetch('https://httpbin.org/get')
3reactions
gugucommented, Apr 3, 2019

Probably we did not understand each other. The documentation says, that if I don’t provide headers parameter, it will be generated automatically and will include ‘Accept’, ‘Content-Length’, … headers.

It is not clear, what happens if I provide ‘User-Agent’ header only. Will it still add Accept, Content-Length, … headers or not. According to the source code, it will change User-Agent and still generate other headers (Accept, Content-Length). That’s what I expected. Sorry for that misunderstanding

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to reset the default user agent on Firefox - Mozilla Support
Learn how to reset your Firefox "user agent" so that websites can detect your correct browser and version and work the way they...
Read more >
How to Change User-Agents in Chrome, Edge, Safari & Firefox
3. Navigate to Develop > User-Agent ... You can again select from a predefined list or enter custom user-agent string by choosing “Other…”...
Read more >
How can I permanently change the default user agent in ...
In edge, I can change the default user agent in Chrome. I can do the following right now: In Edge, select More Tools->Developer...
Read more >
How to Change User-Agent in Chrome, Firefox, Safari, and more
To undo the user-agent change, you will have to return to the same Develop menu and select Default in the User Agent option....
Read more >
How to change your user agent for Firefox
How to change your user agent in Firefox · Open a new tab · Browse to "about:config" · Dismiss the warning · Create...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found