How to save scraped data from client-side browser to a user file? Use Electron?

I want to pull data (maybe scrape) from a web site and save it to an external file.

My first thought was to write a Chrome extension to do that for me, but I could not find how to save to an external file. (I am a newbie with Chrome extensions.) I searched StackOverflow and found answers:

“You can’t do that in a Chrome extension.”,
“You can do it, but I’m not going to tell you how. ;)”
“Use localStorage”

localStorage does not write to a user external file, and I may need to save many MB of data.

My second thought is to use Electron and write a special-purpose browser for the task. Electron has node built-in, so saving a file is possible.

Before I put time and energy into doing this, has anyone already tried it? Any pitfalls or roadblocks ahead?

Read file from disk in Chrome Extensions [duplicate]

This question already has an answer here:

I have data saved in Chrome Storage, and I created export (backup) function which takes these data and download it as JSON file.

Next I would like to create restore function, for example it shows Open File Dialog to user and user can select file and then I parse it.

But I don’t know how can I read some file in user’s file system, is it possible? And if it is not possible, how can I make restore function (any other solution)?

How can we upload a file to a chrome extension?

I am trying to make an extension to transfer files. But I cannot find the api to transfer file. I found some api(fileSystem) but it only works with chrome apps, it does not work with extension. I am working on Google Chrome Extension.

Create file in Chrome Extensions

I would like to know how is it possible to create custom file located in extension root directory using JavaScript or Chrome API.

Extension root directory looks like:

  • popup.html
  • popup.js
  • manifest.json
  • icon.png

And I would like to create JSON file called test in that root directory.

So after that it should look like:

  • popup.html
  • popup.js
  • manifest.json
  • icon.png
  • test.json

test.json should contain:

  "data": "123456789"

It is not duplicate, because that post is for File Dialog and I need to save it at fixed location and in extension folder. And as I said I want to create it, not download it.

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.