Recently, whilst working on some Hive blockchain-related work I opted to use the wonderful dhive package for some client-side operations. Sadly, I soon encountered a serious bug which completely renders the package unusable in a browser environment (Node is fine). The first place I went to was the issues on the Git repository.
Sure enough, it was reported six days ago by
There is actually a Chromium bug open for this here. It seems there has been a little bit of flip-flopping on this and confusion around the Fetch specification and if it specifically allows the User-Agent header to be set.
This was a two-prong issue. Firstly, a library called cross-fetch was being used for the browser Fetch implementation when the whatwg-fetch library was already installed and is more spec-compliant. For the browser, we only need a lighter and browser-specific polyfill.
Secondly, the code that sets the user agent is conditionally set depending on the environment (browser or Node). Because of the aforementioned browser "bug", we check for self to determine if we are in a browser or node environment. Because the code in question was only setting the user agent, it's not crucial from a browser perspective.
If self is undefined, we are in a Node environment. The reason we check using self is that tools like Webpack and compiled JS mock the window object, as well as other possible determinants like exports and so on which have been used in the past to determine a Node environment.
The pull request has been created here and now merged.