Skip to content

Instantly share code, notes, and snippets.

@devAgam
Created June 12, 2023 07:30
Show Gist options
  • Save devAgam/d88bb2acb613cf5f3af9b116e4f93c46 to your computer and use it in GitHub Desktop.
Save devAgam/d88bb2acb613cf5f3af9b116e4f93c46 to your computer and use it in GitHub Desktop.
Sample Function to Automate File Uploads through browser extensions
// 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