How to upload an attachment/file to the Gmail compose window using JS (google chrome extension app)

I am working on a chrome extension built using JS, and looking for a solution to upload files/attachments to Gmail’s compose window from a document management system.

I have the file details (binary data) of the files to upload. And no visibility on next steps to interact with the compose window and uploading file to it.

Can anyone help me in guiding through this please.

Read .webm file from filesystem:chrome-extension://EXTENSION ID/persistent/ and create JavaScript File from it

I’m writing an Chrome Extension for screen capturing, which records video to .webm file inside filesystem:chrome-extension://EXTENSION ID/persistent/myfile.webm and later I need to upload this file through my website, so I need to have recording as a File JavaScript object which can be uploaded.

I tried using this code to fetch a file (I found it somewhere else on SO):

function urltoFile(url, filename, mimeType) {
    return (fetch(url)
        .then(function (res) {
            return res.arrayBuffer();
        })
        .then(function (buf) {
            return new File([buf], filename, {
                type: mimeType
            });
        })
    );
}

I call it with this code:

urltoFile("filesystem:chrome-extension://EXTENSION ID/persistent/myfile.webm","myfile.webm","video/webm").then(function (file) {
    //Here I would do something with the file
}

but all I get is this error:

Uncaught (in promise) TypeError: Failed to fetch

I’m wondering how can I achieve what I need?