admin管理员组文章数量:1287961
Sometimes, one needs to add special headers to each request or specific requests made from a browser. The mon approach to do this is by using browser extensions which allow us to modify request headers. Is there another way to do this, without any browser extension ?
PS - I have searched SO and not found a single post which actually suggests or shows how to do what I need.
Sometimes, one needs to add special headers to each request or specific requests made from a browser. The mon approach to do this is by using browser extensions which allow us to modify request headers. Is there another way to do this, without any browser extension ?
PS - I have searched SO and not found a single post which actually suggests or shows how to do what I need.
Share Improve this question asked Dec 28, 2017 at 1:12 Erran MoradErran Morad 4,75311 gold badges45 silver badges76 bronze badges 2- is using a proxy an acceptable solution to you? – user10864482 Commented Jan 15, 2019 at 20:09
- @User23332 - sounds acceptable. – Erran Morad Commented Jan 21, 2019 at 6:07
3 Answers
Reset to default 9Outside of APIs designed to make custom HTTP requests (XMLHttpRequest and fetch), it is impossible to add arbitrary HTTP headers to requests made by browsers using JS embedded in a page.
If you control the websites that you want this functionality on, you could achieve this by setting each application to install a ServiceWorker. In a nutshell, service workers run as a proxy server within your browser. They can do things like notify you of updates even if you don't have the website open.
Within a ServiceWorker you are able to set up event listeners that can do some asynchronous task on behalf of the client app. This includes the fetch
event which is fired every time the web page makes a request.
Here's a write up on someone implementing a ServiceWorker who also needed to intercept network requests. You could follow most of this and just alter the logic when inspecting the request type. At that point you could add any special headers before dispatching on the applications behalf.
Theres no possibility to edit requests in existing DOM without using any external tools. The most suitable is Browser Extension which is editing the existing DOM and HTTP requests (XMLHttpRequest and fetch) done by JavaScript code.
Theres millions of possibilities to add headers to requests if the owner of website is you. And the solutions are different consider on what lib are you using for doing requests.
But in general it's not remended to modify website data that is not yours.
The Browser Extension is the exact thing that you found for your problem. Hope my ment will help you.
本文标签: javascriptHow to add headers to a browser request without any browser extensionsStack Overflow
版权声明:本文标题:javascript - How to add headers to a browser request without any browser extensions? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741272745a2369558.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论