'How to use chrome.pageCapture.saveAsMHTML()?

I am building a chrome extension that will parse through the HTML of whatever website the user is viewing for metadata.

I am super new at using the chrome API, and I am trying to figure out how to use chrome.pageCapture.saveAsMHTML(object details, function details). These parameters are pretty confusing to me.... I was trying to use http://developer.chrome.com/extensions/pageCapture but I haven't figured it out yet.

How do i assign the MHTML to a variable so that I can begin parsing?



Solution 1:[1]

chrome.pageCapture.saveAsMHTML({ tabId: tab.id }, async (blob) => {
    const content = await blob.text();
    const url = "data:application/x-mimearchive;base64," + btoa(content);
    chrome.downloads.download({
        url,
        filename: 'filename.mhtml'
    });
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TSO