Let’s say you want Chrome to automatically download pieces of pages,
such as Facebook comments. How could you
do it? I recently wanted to do this and couldn’t find docs, so here’s
what I did.
Make a folder somewhere for a browser extension.
In that folder, make manifest.json with contents
like:
// This file extracts what you want from the page
// and asks the background script to save it.
// You write the code to extract what you want.
const yourStringToSave =
yourFunctionToExtractFromPage();
chrome.runtime.sendMessage(
/* extension id not needed */ undefined,
[fileNameToUse,
yourStringToSave]);
In background.js put:
// This file receives messages from the content
// script and puts them in your Dowloads folder.
function makeDataUrl(body) {
// We use a data: url because Chrome has
// trouble with object URLs in Incognito.
return “data:application/json;base64,” +
btoa(unescape(encodeURIComponent(body)));
}
chrome.runtime.onMessage.addListener(
function(message) {
const fname = message[0];
const body = message[1];
chrome.downloads.download({
conflictAction: “overwrite”,
filename: fname,
url: makeDataUrl(body),
});
});
Visit chrome://extensions
Enable Developer Mode
Click the “Load unpacked” and select the extension directory
If you need it in Incognito, click “Details” on the extension
card and then enable “Allow in Incognito”.
Auto-Downloder Chrome Extension
Link post
Let’s say you want Chrome to automatically download pieces of pages, such as Facebook comments. How could you do it? I recently wanted to do this and couldn’t find docs, so here’s what I did.
Make a folder somewhere for a browser extension.
In that folder, make
manifest.json
with contents like:In
content_script.js
put:In
background.js
put:Visit
chrome://extensions
Enable Developer Mode
Click the “Load unpacked” and select the extension directory
If you need it in Incognito, click “Details” on the extension card and then enable “Allow in Incognito”.
Example code: github.
(And, yes, this is how Facebook comments are back.)