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 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 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-

My content.js is –

var xhr = new XMLHttpRequest();'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:
                        console.log(lines[line]);   //prints:
                        var linestr = lines[line];
                        console.log(link.indexOf(linestr));  // prints: -1
                        console.log(link.indexOf("") !== -1);  // prints: true
                        if(link.indexOf(lines[line]) !== -1)
                            console.log("Link Matched!");

I can't understand why link.indexOf(lines[line]) is -1 when link is and lines[line] is But link.indexOf("") returns 0 as index.