How to efficiently export large data array to CSV in Chrome?

I’m writing a Google Chrome extension that should work with really big arrays of data (1k-30k entries, each has 9-10 fields). I need to export this to CSV (not JSON). Don’t ask me why, that’s the task, the data should be readable and ready for import into Excel and Google Sheets for example).

For now building a string in a simple for() loop takes about 30-40 seconds (and the extension view has to be opened for all this time in order for the script to complete), which is in fact even more than the time needed to parse that data from the online source which is monitored by the extension. That’s absolutely intolerable for the end user. Are there any ways to achieve the goal without writing a server side with SQL storage and retrieving CSV from server?

Pushing a local storage array onto another array

Hello all I am attempting to add testList as an element to the holdTestList array. Currently the variables get overwritten every time due to the sync.set however i am trying to store all of them through declaring a new list holdTestList and pushing the list obtained through the sync.get (testList) onto it

theSettingScript.js

testList.push(var1, var2, var3);
    chrome.storage.sync.set({
    list:testList,
    }, function() {
    console.log("added to list");   
    });

theGettingScript.js

   window.addEventListener('load', getContents);

    var holdTestList = []; // THIS ARRAY IS USED TO STORE THE ORIGINAL LIST AND THE NEW LISTS ADDED TO IT

    function getContents () {
    chrome.storage.sync.get({
        list:[] 
    },
    function(data) {
       console.log(data.list);
       holdTestList.push(data.list); // Putting the new variables into the full array
    });  
    }

Javascript check if HTML contains an item from an array

I have a list of potential html classes in my javascript file

var html_list = ["blogrss",
"btnrss",
"buttonsrssfeed",
"copypasteblocker",
"facebook128x128",
"feedicon",
"iconrss",
"instagram128x128",
"jobwidget",
"pinterest128x128",
"pushnotification",
"rss128x128"]

Upon visiting a webpage i would like to iterate the array and if the webpage contains one of the elements a simple alert will show which html element the page contains.

Javascript Array.length is incorrrect

I have an array of objects which initially has 4 elements. The array.length is proper when I console.log initially. Later I push one more object to the array. The Item is added to the array but the Array.length is incorrect this time. Please have a look at the screenshot

Does someone have any idea what causes this issue

enter image description here

How to make image array shuffle script work in google chrome extension?

I’m new to chrome extensions and javascript so this may be a pitiful question.
I am trying to make a popup where an image appears and then after a user presses a button, the image changes after each button; all images are stored in an array.
This is what my arrayShuffle.js looks like.

  var imagesArray = ["https://i.pinimg.com/originals/93/95/32/939532994e66f1a626362e17e9daab54.jpg", "https://i.pinimg.com/originals/39/9d/13/399d13fea473ef21532f1cba01130327.jpg", "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTrv2lY60BseySP27SOC4tOzY_qxjxauxkst4W-wOLd87bKkvuk"];
function displayImage(){
    var num = Math.floor(Math.random() * imagesArray.length);
    document.canvas.src = imagesArray[num];
  }

Here is my .html file simplified:

I realize I’m new to both javascript and chrome extensions, but I’m still confused about this not working.

Why is papaparse making incorrect subarrays? Dividing data into [0..99][100] array instead of [0][1]…[100]

My code

parse(files: FileList): void {
        const file: File = files.item(0);
        const reader: FileReader = new FileReader();
        reader.readAsText(file);
        reader.onload = e => {
            const csv = reader.result;
            const parsed = this.papaParse.parse(csv, { header: false });
            this.papaParse.parse(csv, {
                complete: (results, file) => {
                    console.log('Parsed', results, file);
                    this.results = results;
                }
            });


        }

    }

It outputs like this
enter image description here

I was expecting the data array to have subarray with the information not another set of arrays.
How do I fix this?

Why is chrome giving me a TypeError when finding largest number in array?

I have the following code to find the largest number in an array:

function max(input) {
 var maxNum = 0;
 for(var i = 0; i <= input.length; i++) {
     if(maxNum < input[i]) {
         maxNum = input[i];
        }
    }
    return maxNum;
}
max([1, 2, 3, 7]);

When I run it in Google Chrome, Edge, or Firefox I get:

max.js:20 Uncaught TypeError: Cannot read property 'length' of undefined
    at max (max.js:20)
    at :1:1

but when I run it on pythontutor for JavaScript, I get the correct results without any syntax error.

chrome.tabs.query does not find match if url property is an array

I’m building a chrome extension and trying to get an array of tabs using chrome.tabs.query({url: arrayOfUrls}):

chrome.tabs.query({url: this.tabUrlsList}, function(tabs){
            var ids = [];
            if(tabs){   
                //creates an array of intergers (tab ids)

                for(var i = 0; i < tabs.length; i++){
                    ids[i] = tabs[i].id;

                }
                console.log(tabs.length)
                console.log(ids)
                \move stuff around using the tabs' ids

The "if" statement I added after i got the following problem (and it hasn't fixed it): the console.log sometimes displays the correct number, and ids, but in many cases shows only one tab queried. Seems quite odd. I found no references to this question anywhere, except for this: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9107332/
but its from two years ago almost.
if its a windows thing I'm using windows 7.
help will be much appreciated.

How do I locally save the urls visited by an user, through a chrome extension, using JS?

I want to save the url link of the active tab, through a chrome extension, when an user clicks on the extension icon. The url should be saved in local storage, and should remain stored until the active window isn’t closed. I am trying to save the url in an array tablink

Here’s the manifest.json

{
    "manifest_version": 2,

    "name": "saveLink",
    "version": "1.0",

    "browser_action": {
        "default_icon": "xyz.png",
        "default_popup": "popup.html",
        "default_title": "saveLink"
    },
    "permissions": [
        "activeTab",
        "storage",
        "tabs"
    ]
}

Here’s my popup.js which contains the js code for popup.html

var tablink = [];
function getTabUrl(){
  chrome.tabs.getSelected(null,function(tab) {
  var len = tablink.length;
  if(len == 0){
  tablink[0] = tab.url;
}
else{
  tablink[len] = tab.url;
}
console.log(tablink);
 }
}

document.addEventListener("DOMContentLoaded", function() {
  getTabUrl();
  link.addEventListener('click', function() {
    chrome.tabs.update({url: 'https://www.google.com/'});
  });
});

Currently, the console isn’t printing anything. Also, the extension has a button which redirects to the specified link(google.com), which was working fine before I wrote the code for saving tab links, but now isn’t working. Please specify if anything more needs to be added.

How do I delete one item from an array with chrome.storage.sync.remove?

I’m building a Chrome browser extension which includes a feature that lets users save urls. I used chrome.storage.sync to create this feature and didn’t encounter any issues.

However, I also need to let users delete urls they’ve already saved. I created a text input box where they can enter a single url they want to delete (i.e. “www.url.com”). I want to convert this input into a string and use it to remove a matching string from Chrome storage when the user presses a button.

I thought the chrome.storage documentation specifies that chrome.storage.sync.remove can be used to remove a string from a stored array, but I can’t get it to work. Here’s my code:

function removeUrl() {
    var theUrl = document.getElementById('url-input').value;
    chrome.storage.sync.get(null, function(result, error) {

        // Checks if the array (urlList) exists:
        if ('urlList' in result) {
            var theList = result['urlList'];

            // Checks if the url that will be deleted is in the array:
            if (theList.includes(theUrl)) {
                chrome.storage.sync.remove(theUrl);
                chrome.runtime.reload();
            }
        }
        // Error handling goes here
    });
}

This code doesn’t throw any errors, but it doesn’t remove the url from the array either.

Please note that I only want to delete 1 url at a time, there are no duplicate urls in the array, and I am not using any libraries like jQuery. What am I doing wrong?