0

When I run my code, it first logs the URL of the network request then when I try logging the body, it just says undefined. When I click on the URL link that is logged in the console from the first console.log, it downloads the js file onto my PC that I am trying to print. Is there something wrong with my requestBody or is there another way of printing the content of the js file into the console without having to open it?

//background.js
function logURL(requestDetails) {

    if (requestDetails.url.includes("getMe"))
    {
      console.log(requestDetails.url)
       console.log(requestDetails.requestBody) 
    }

  }
  chrome.webRequest.onBeforeRequest.addListener(
    logURL,
    {urls: ["<all_urls>"]},
    ['requestBody']
  );
Nicky
  • 57
  • 1
  • 1
  • 7
  • 1) Did you add the site to `host_permissions` (MV3) or `permissions` (MV2)? 2) Maybe you need the body of the response from the server, not the request from the browser? – wOxxOm Mar 29 '22 at 19:18
  • @wOxxOm using MV2 "permissions": [ "tabs", "storage", "webRequest", "webRequestBlocking", "onBeforeRequest", "", "requestBody" ] – Nicky Mar 29 '22 at 19:40
  • Maybe you need the body of the response from the server, not the request from the browser? – wOxxOm Mar 29 '22 at 19:49
  • Yes I believe that it is the case? Does my code not do that? – Nicky Mar 29 '22 at 19:58
  • No, this code is for the body of the request from the browser i.e. the data sent to the server. – wOxxOm Mar 29 '22 at 21:31

0 Answers0