Created
April 20, 2025 17:38
-
-
Save avirajkhare00/ed9964eb734993510288935ff76a7760 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function fetchAndDownload(url, filename) { | |
try { | |
const response = await fetch(url); | |
const blob = await response.blob(); | |
const link = document.createElement('a'); | |
link.href = URL.createObjectURL(blob); | |
link.download = filename; | |
link.click(); | |
URL.revokeObjectURL(link.href); | |
} catch (error) { | |
console.error('Error:', error); | |
} | |
} | |
const downloadLink = document.getElementsByTagName('video')[0].src; | |
const fileName = 'some_file.mp4'; | |
fetchAndDownload(downloadLink, fileName); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment