chrome.webRequest.onBeforeRequest get access to the post payload

366 views
Skip to first unread message

Bogdan Nazaruk

unread,
Nov 13, 2023, 4:42:18 PM11/13/23
to Chromium Extensions
Hey hey people!

Here's my debugging listener: 
  chrome.webRequest.onBeforeRequest.addListener(async info => {
    if(/\/b\/ss\//.test(info.url) && info.method === "POST"){
      sendToTab({
        info: info,
        eventTriggered:"onBeforeRequest",
        _satelliteInfo:JSON.parse(await getSatelliteInfo())
      });
    }
  }, filter);

I receive it in my content script and console.log it.
The info object doesn't seem to contain the payload.

How do I access the POST payload? I actually don't care which listener to use. If it's available in a different listener, I don't mind switching it. I'm still going to have to sync it with my onHeadersReceived.

Thanks a lot!










Bogdan Nazaruk

unread,
Nov 13, 2023, 4:44:20 PM11/13/23
to Chromium Extensions, Bogdan Nazaruk
I think this answers it: https://stackoverflow.com/questions/33106709/chrome-webrequest-doesnt-see-post-data-in-requestbody Gonna try parsing the raw bytes. But if you have a better solution, let me know :)

wOxxOm

unread,
Nov 13, 2023, 5:46:01 PM11/13/23
to Chromium Extensions, Bogdan Nazaruk
`chrome` messaging in Chrome still can't send binary data such as ArrayBuffer or Uint8Array, so you'll need to parse the raw bytes and serialize in a JSON-compatible form e.g. as a conventional array or a base64 string. The latter is the most effective solution in Chrome for big data (if performed via FileReader's readAsDataURL) because sendMessage's won't waste time transcoding the result into UTF-8 internally.
Reply all
Reply to author
Forward
0 new messages