Get response data from intercepted http request

82 Views Asked by At

I'm using Firefox, and creating a personal web extension. I'm trying to get the data returned by GET requests sent out by a website. I can successfully intercept the requests using the background script:

browser.runtime.onInstalled.addListener(() => {
    browser.webRequest.onCompleted.addListener(function(details) {
        console.log(details);
    }, {urls: ["https://www.tumblr.com/*"]});
});

But... the data I get doesn't seem to be what I want. The response is often like:

Object { requestId: "42624", url: "https://www.tumblr.com/api/v2/user/counts?unread=true&inbox=true&unread_messages=true&blog_notification_counts=true&private_group_blog_unread_post_counts=true", originUrl: "https://www.tumblr.com/a-blog", documentUrl: "https://www.tumblr.com/a-blog", method: "GET", type: "xmlhttprequest", timeStamp: 1701137740118, tabId: 128, frameId: 0, parentFrameId: -1, … }
cookieStoreId: "firefox-private"
documentUrl: "https://www.tumblr.com/a-blog"
frameAncestors: Array []
frameId: 0
fromCache: false
incognito: true
ip: "XXX.XXX.XXX.XXX"
method: "GET"
originUrl: "https://www.tumblr.com/a-blog"
parentFrameId: -1
proxyInfo: null
requestId: "X"
requestSize: 0
responseSize: 0
statusCode: 200
statusLine: "HTTP/2.0 200 "
tabId: 128
thirdParty: false
timeStamp: 1701137740118
type: "xmlhttprequest"
url: "https://www.tumblr.com/api/v2/user/counts?unread=true&inbox=true&unread_messages=true&blog_notification_counts=true&private_group_blog_unread_post_counts=true"
urlClassification: Object { firstParty: (2) […], thirdParty: [] }

What's confusing to me here is how it returns "responseSize: 0" despite being able to see a valid response in Inspect. The response I want is json like:

{
  "blog_notification_counts":
  [
    {
      "blog_uuid":"t:<STRING>",
      "count":48
    }
  ],
  "unread":855,
  "inbox":4,
  "unread_messages":
  {
    "<UUID>":
    {
      "XXX":1,
      "XXX":1,
      "XXX":2
    }
  },
  "private_group_blog_unread_post_counts":[],
  "next_from":1701137956
}

The important sections are the "blog_notification_counts", "unread", "inbox", and "unread_messages". If anyone has any idea of how to obtain the given 'correct' response data instead of the lack of a response I get from intercepting it (it still updates correctly i think!?) that would be perfect.

Thank you!

What I tried and what I expected:

I wrote the background script to intercept GET requests exiting the website, but the data I got did not contain the response I wanted.

0

There are 0 best solutions below