Created
June 12, 2023 07:30
-
-
Save devAgam/d88bb2acb613cf5f3af9b116e4f93c46 to your computer and use it in GitHub Desktop.
Sample Function to Automate File Uploads through browser extensions
This file contains 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
// This function does the following | |
// 1. fetches the PDF resume from the url provided | |
// 2. creates a file object with the resume data | |
// 3. triggers the change event on the file input element | |
// 4. the file input element gets the file object | |
// 5. the file object is uploaded to the website | |
async function handleResumeInput(remoteResumeURL) { | |
const designFile = await createFile(remoteResumeURL); | |
const input = document.querySelector('input[type="file"]'); | |
const dt = new DataTransfer(); | |
dt.items.add(designFile); | |
input.files = dt.files; | |
const event = new Event("change", { | |
bubbles: !0, | |
}); | |
input.dispatchEvent(event); | |
} | |
async function createFile(url) { | |
let response = await fetch(url); | |
let data = await response.blob(); | |
let metadata = { | |
type: "application/pdf", | |
}; | |
return new File([data], "resume.pdf", metadata); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment