1

I am trying to achieve the following. I have a chrome extension which performs a page capture using chrome.pageCapture API. It returns a blob containing an MHTML file. I then create a new FormData object, attach my blob to it and pass it to the XMLHttpRequest function. Here's the full code that does it:

        chrome.tabs.query(queryOptions, (tabs) => {
            let tab = tabs[0];
            chrome.pageCapture.saveAsMHTML(
              {tabId:tab.id},
              function(mhtml) {
                let xhr = new XMLHttpRequest();
                let formData = new FormData();

                formData.append("mhtml", mhtml);

                xhr.open("POST", "http://localhost:8080", true);
                xhr.send(formData);
              }
            )
        });

I then try to save this MHTML file to disk using Node.js. In order to do that I created and started a local server on port 8080 and am listening for requests there. My POST request comes in fine, and I assume saving it would entail converting it back to a Buffer and using something like fs.writeFile('page.mhtml', buffer);

But I am not quite sure what's the correct way of extracting my blob from the request. Any tips would be very welcome.

Thank you!

Lukich
  • 686
  • 1
  • 10
  • 20

0 Answers0