I want to write a Chrome extension that saves to the disk the entire web page (at least the text and the links), just before the tab is closed or refreshed or loaded with another URL.
(Some websites generate different feed every time you refresh. This extension is meant for locally persisting the previous feeds of such sites. Saving pages right after they are loaded is not good because it misses the feeds that may appear later during the infinite scroll.)
I tried listening to the onUpdated event, but it seems to return the new content not the pre-reload one:
// background.jschrome.tabs.onUpdated.addListener(function(tabId,changeInfo,tab) { if (tab.url !== undefined && changeInfo.status == "complete"){ chrome.pageCapture.saveAsMHTML({"tabId": tabId}, function(mhtmlData){ let mhtmlBlob = new Blob([mhtmlData], { type: 'application/x-mimearchive' }); // save mht }); }});
Fiddling with different values of changeInfo.status
etc did not help either. Should I check out onRemoved and onReplaced? Any suggestions?
PS: This related question talks about closing of a window while I am interested at the tab level.