How to save file to a server in JavaScript in a Chrome extension?

I need to be able to modify and save a file on my website from my Chrome extension.

I’m not sure how to begin saving.

How to do so? Thanks!

chrome extension that loads files from disk and plays music in background

I am creating a chrome extension that loads files from disk and plays music in the background.
I have a popup.html page that has an input element that loads audio files, converts them into dataURL and sends it to the background page, which is loaded into an audio element.

Now chrome doesn’t allow me to directly access the file from disk through the background page. also, I’m not allowed to send the file from the popup to the background page directly. I can’t use chrome.storage as a means of transferring the files also. so the only thing i can do is convert to dataURl and send.(if there are any other means of file transfer. please let me know)

the problem is when I select a lot of music files, the dataURL strings take up a lot of memory. this could cause performance issues, especially on systems with low ram.

so whats the most memory efficient way to send, store and load these audio files?
and also I tried using chrome.storage but there was a problem with the quota management.

anyways thanks for all the help!

Text file line doesn’t match with string indexOf()

My Chrome extension will show if a link in a text file matches any link in current tab’s html. The text file is like-

https://www.facebook.com/groups/929402513755249/
https%3A%2F%2Ficpc.baylor.edu%2F
https%3A%2F%2Fvjudge.net%2Fcontest%2F187074

My content.js is –

var xhr = new XMLHttpRequest();
        xhr.open('GET', chrome.extension.getURL('file.txt'), true);

        xhr.onreadystatechange = function()
        {
            if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200)
            {
                var allText = xhr.responseText;
                //var lines = allText.split('n');

                for (var i = 0; i < document.links.length; i++) {
                    var link= document.links[i].href;
                    var lines = allText.split('n');

                    for(var line = 0; line < lines.length; line++){
                        console.log(link);   // prints: https://www.facebook.com/groups/929402513755249/#
                        console.log(lines[line]);   //prints: https://www.facebook.com/groups/929402513755249/
                        var linestr = lines[line];
                        console.log(link.indexOf(linestr));  // prints: -1
                        console.log(link.indexOf("https://www.facebook.com/groups/929402513755249/") !== -1);  // prints: true
                        if(link.indexOf(lines[line]) !== -1)
                        {
                            console.log("Link Matched!");
                        }
                    }
                }
            }
        };
        xhr.send();

I can't understand why link.indexOf(lines[line]) is -1 when link is https://www.facebook.com/groups/929402513755249/# and lines[line] is https://www.facebook.com/groups/929402513755249/. But link.indexOf("https://www.facebook.com/groups/929402513755249/") returns 0 as index.