javascript - How do I console.log POST requests with my chrome extension - Stack Overflow

I'm trying to console.log POST requests with my chrome extension but can't figure out how to

I'm trying to console.log POST requests with my chrome extension but can't figure out how to do it, can anyone give me an example? I've looked at the chrome extension API but still can't seem to get to it

I'm trying to console.log POST requests with my chrome extension but can't figure out how to do it, can anyone give me an example? I've looked at the chrome extension API but still can't seem to get to it

Share Improve this question asked Aug 15, 2017 at 5:56 PeterPeter 211 silver badge2 bronze badges 5
  • are you trying to create an extension that "listens" to requests and logs something when it sniffs one out? if so, then read the documentation for webRequest - it's straight forward - there's even a link to samples on that page – Jaromanda X Commented Aug 15, 2017 at 5:59
  • I think this answer help you how to print the data from post request on console – Emre Gozel Commented Aug 15, 2017 at 6:12
  • Where to read console messages from background.js in a Chrome extension? – woxxom Commented Aug 15, 2017 at 6:17
  • Yes I am @JaromandaX I'm trying to figure it out now. Struggling but I'm sure I'll get there in the end :) – Peter Commented Aug 15, 2017 at 6:27
  • try writing code, then when you have a specific problem with your code, ask again :p – Jaromanda X Commented Aug 15, 2017 at 6:33
Add a ment  | 

1 Answer 1

Reset to default 4

In Google Chrome, browser requests such as POST and GET are visible in the Network tab of the Inspector.

Screenshot from Chrome Devtools Overview:

If you are looking for a natural way to make a Javascript hook on browser requests (such as for logging them out), you will have more issues as there is no native way for Javascript to hook on requests at browser's scale, for security reasons.

But if you are okay to use a dedicated extension for the job, you can look at the webRequest extension for Chrome:

https://developer.chrome./extensions/webRequest

Use the chrome.webRequest API to observe and analyze traffic and to intercept, block, or modify requests in-flight.

Here's an example of listening for the onBeforeRequest event:

  chrome.webRequest.onBeforeRequest.addListener(callback, filter, opt_extraInfoSpec);

Beware, there are security requirements and limitations:

You must declare the "webRequest" permission in the extension manifest to use the web request API, along with host permissions for any hosts whose network requests you want to access.

Note that due to the ordered or asynchronous nature of the webpage resources loading (HTTP/1.x or HTTP/2.0) you are not be guaranteed to catch all the requests made by the browser that happened before your Javascript hooks were setup.

Eventually, you have some tricks, such as those referenced here for detecting AJAX calls through Javascript proxification mechanisms.

Another strategy would be to have the request detection deported on server and informing the client he sent a request (through Websockets/queues for example). It would only work for requests targeted on the domains you manage though, and it sounds like a bit of an expensive solution. It all depends of what your ultimate needs are.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745315569a4622202.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信