Brilliant
Staff member
- Joined
- Dec 31, 2024
- Messages
- 378
- Reaction score
- 7
- Points
- 18
- User icon
- <svg xmlns="http://www.w3.org/2000/svg" height="14" width="15.75" viewBox="0 0 576 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path fill="#63E6BE" d="M309 106c11.4-7 19-19.7 19-34c0-22.1-17.9-40-40-40s-40 17.9-40 40c0 14.4 7.6 27 19 34L209.7 220.6c-9.1 18.2-32.7 23.4-48.6 10.7L72 160c5-6.7 8-15 8-24c0-22.1-17.9-40-40-40S0 113.9 0 136s17.9 40 40 40c.2 0 .5 0 .7 0L86.4 427.4c5.5 30.4 32 52.6 63 52.6l277.2 0c30.9 0 57.4-22.1 63-52.6L535.3 176c.2 0 .5 0 .7 0c22.1 0 40-17.9 40-40s-17.9-40-40-40s-40 17.9-40 40c0 9 3 17.3 8 24l-89.1 71.3c-15.9 12.7-39.5 7.5-48.6-10.7L309 106z"/></svg>
No, the chrome.webRequest API does not capture the requestBody of PATCH requests. The requestBody is only available for requests made using the POST method.
According to the official Chrome Extensions documentation for webRequest, the webRequest.onBeforeRequest event provides access to the requestBody, but this is limited to POST requests.
Why Doesn't It Work for PATCH?
This limitation is due to how the API was designed. Chrome does not expose the requestBody for other HTTP methods like PATCH, PUT, or DELETE. It is likely a security or privacy-related decision made by the Chrome development team.
---
Workarounds
If you need to capture the requestBody for PATCH requests, here are some alternative approaches:
1. Use a Content Script to Intercept Fetch/XHR
You can inject a content script into the web page and override fetch or XMLHttpRequest to capture the body of PATCH requests. For example:
> Note: This approach works only for requests initiated by the web page itself, not for background requests made by other extensions or the browser.
---
2. Proxy Server
If you control the server or can proxy the traffic, you can inspect and log the PATCH request body on the server side.
---
3. Migrate to Manifest V3 and Declarative Net Request API
The chrome.webRequest API is being deprecated in Manifest V3 in favor of chrome.declarativeNetRequest. However, the new API is even more restrictive and does not allow access to request bodies at all. If you are planning to migrate, be aware that you will need to rely on alternative methods (like the content script method above).
---
Conclusion
The chrome.webRequest API cannot directly capture the requestBody of PATCH requests. You will need to use a workaround like content scripts or server-side logging.
According to the official Chrome Extensions documentation for webRequest, the webRequest.onBeforeRequest event provides access to the requestBody, but this is limited to POST requests.
Why Doesn't It Work for PATCH?
This limitation is due to how the API was designed. Chrome does not expose the requestBody for other HTTP methods like PATCH, PUT, or DELETE. It is likely a security or privacy-related decision made by the Chrome development team.
---
Workarounds
If you need to capture the requestBody for PATCH requests, here are some alternative approaches:
1. Use a Content Script to Intercept Fetch/XHR
You can inject a content script into the web page and override fetch or XMLHttpRequest to capture the body of PATCH requests. For example:
> Note: This approach works only for requests initiated by the web page itself, not for background requests made by other extensions or the browser.
---
2. Proxy Server
If you control the server or can proxy the traffic, you can inspect and log the PATCH request body on the server side.
---
3. Migrate to Manifest V3 and Declarative Net Request API
The chrome.webRequest API is being deprecated in Manifest V3 in favor of chrome.declarativeNetRequest. However, the new API is even more restrictive and does not allow access to request bodies at all. If you are planning to migrate, be aware that you will need to rely on alternative methods (like the content script method above).
---
Conclusion
The chrome.webRequest API cannot directly capture the requestBody of PATCH requests. You will need to use a workaround like content scripts or server-side logging.