Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify the response body of HTTP requests with Chrome extension [duplicate]

I am working on a Chrome extension. I would like to modify some contents when the (very first) page load happens. I wonder if I use the method getContent() in chrome.devtools.network.onRequestFinished.addListener, how can I modify the content after it is returned from the method?

Is this method only for network/traffic observation? Can I modify the response body?

like image 597
pjk Avatar asked Jun 25 '13 13:06

pjk


People also ask

How do I edit and resend in Chrome?

In the Network panel of devtools, right-click and select Copy as cURL. Paste / Edit the request, and then send it from a terminal, assuming you have the curl command.

How do I get the HTTP request body in Chrome?

To view the request or response HTTP headers in Google Chrome, take the following steps : In Chrome, visit a URL, right click , select Inspect to open the developer tools. Select Network tab. Reload the page, select any HTTP request on the left panel, and the HTTP headers will be displayed on the right panel.


1 Answers

This has never been possible.

See this bug in the Chromium project (from Nov. 2011):

  • https://bugs.chromium.org/p/chromium/issues/detail?id=104058

There are a couple relevant discussions on how to work around this limitation for certain use cases:

  • Insert code into the page context using a content script
  • https://groups.google.com/a/chromium.org/forum/#!msg/apps-dev/v176iCmRgSs/iM-72Evf8JgJ

Based on some of the discussion in the Chromium bug DB, I'd guess that modifying the content of the existing request may never be allowed for security reasons, but reading the response and redirecting might be allowed (someday when all the blocking issues are resolved).

like image 179
lobacten Avatar answered Sep 21 '22 09:09

lobacten