Friday, May 1, 2020

Script to Download Facebook Videos

How to download a video from sites is a recurrent question of every users. In this article it is described a simple method which allows download either private and public videos from Facebook just by adding a bookmark with some javascript to your browser.

A 'bookmarklet' is a bookmark stored in a web browser that contains JavaScript commands that add new features to the browser. The way to add a bookmarklet is as simple as write a JavaScript function, and call it with the `javascript:` URL protocol

But first we need to encode the function

In our case, to download a Facebook video the function needed is:
  fetch(location.pathname, {method: 'GET'})
    .then((r) => r.text())
    .then(html => new DOMParser().parseFromString(html, 'text/html'))
    .then(d =>'meta[property="og:video"]')[0].content, '_blank'))

Thus, the fragment that should be copied and pasted the the bookmark is:

The following video shows how to add the bookmarklet to Chrome, and how to use it.