What's new
  • Do not create multi-accounts, you will be blocked! For more information about rules, limits, and more, visit the Help Page Found a dead link? Use the report button!
  • If no files are available, please contact me or reply in the thread. I will update them immediately.

Does chrome.webRequest capture the "requestBody" of PATCH?

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:

JavaScript:
// Content script

(function () {

    const originalFetch = window.fetch;

    window.fetch = async function (...args) {

        const [resource, config] = args;

        if (config && config.method === "PATCH") {

            console.log("Intercepted PATCH body:", config.body);

        }

        return originalFetch.apply(this, args);

    };



    const originalXHR = window.XMLHttpRequest.prototype.open;

    window.XMLHttpRequest.prototype.open = function (method, url) {

        this.addEventListener("readystatechange", function () {

            if (method === "PATCH" && this.readyState === 4) {

                console.log("Intercepted PATCH XHR body:", this._body); // Capture body if stored

            }

        });

        return originalXHR.apply(this, arguments);

    };

})();

> 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.
 
Back
Top