2

I'm embedding a large array in Javascript for the development of a Chrome extension. The extension is essentially supposed to contain a dataset of over 23.000 entries. This is all very new to me. Apologies for any unclarity; I will try to make this as clear as possible.

At about 13.200 unique entries, the extension works fine. If I try to add any more unique entries, the extension no longer works (i.e. won't show up in the address bar).

Now, at first I figured this was a size issue, but this seems not to be the case, seeing as the extension works fine with up to 90.000 entries, as long as the entries beyond the 13.200 point were replicas of the entries before the 13.200 point (i.e. no new uniques).

This is the part of the code that's causing trouble:

var dataSet = [ 
["Example Company A", "23.760.90","22.760.90","0","21.000.00","0","0","0","0","0","0" ],
["Example Company B", "13.800.90","22.860.90","0","21.000.00","0","0","0","0","0","0" ]
["Example Company C", "63.960.90","10.460.90","0","21.000.00","0","0","0","0","0","0" ]
//etc. (23.000 times)
];

After doing some research, I figured the problem might have to do with parsing the source code - as was outlined here: Have I reached the limits of the size of objects JavaScript in my browser can handle?

"To summarize the comment quagmire on Juan's answer: I had to split up my big array into a series of smaller ones, and then Array#concat() them, but that wasn't enough. I also had to put them into separate var statements. Like this:

var arr0 = [...];
var arr1 = [...];
var arr2 = [...];
/* ... */
var bigArray = arr0.concat(arr1, arr2, ...);

So I tried this suggestion - but it did not make any difference. That is, the extension did not recognize any new entries beyond the 13.200 point.

At this point, I'm not sure what to try anymore, seeing as I'm not even sure what the exact issue is.

My questions

  • Could this be a size issue after all?

  • Did I miss something here while splitting the arrays?

  • Is there another way to go about including a dataset for a Chrome extension? (e.g. Ajax call)

Here's the background.js file:

[previous bit of code goes here (i.e. var dataSet = [] )

$(document).ready(function() {
$('#demo').html( '<table cellpadding="0" cellspacing="0" border="0" class="display" id="example"></table>' );

chrome.tabs.query({currentWindow: true, active: true}, function(tabs){

    function parseURL(url){
parsed_url = {}

if ( url == null || url.length == 0 )
    return parsed_url;

protocol_i = url.indexOf('://');
parsed_url.protocol = url.substr(0,protocol_i);

remaining_url = url.substr(protocol_i + 3, url.length);
domain_i = remaining_url.indexOf('/');
domain_i = domain_i == -1 ? remaining_url.length - 1 : domain_i;
parsed_url.domain = remaining_url.substr(0, domain_i);
parsed_url.path = domain_i == -1 || domain_i + 1 == remaining_url.length ? null : remaining_url.substr(domain_i + 1, remaining_url.length);

domain_parts = parsed_url.domain.split('.');
switch ( domain_parts.length ){
    case 2:
      parsed_url.subdomain = null;
      parsed_url.host = domain_parts[0];
      parsed_url.tld = domain_parts[1];
      break;
    case 3:
      parsed_url.subdomain = domain_parts[0];
      parsed_url.host = domain_parts[1];
      parsed_url.tld = domain_parts[2];
      break;
    case 4:
      parsed_url.subdomain = domain_parts[0];
      parsed_url.host = domain_parts[1];
      parsed_url.tld = domain_parts[2] + '.' + domain_parts[3];
      break;
}

parsed_url.parent_domain = parsed_url.host + '.' + parsed_url.tld;

return parsed_url;
}

    var website = parseURL(tabs[0].url).host+"."+parseURL(tabs[0].url).tld;

    $('#example').dataTable( {
        "data": dataSet,
        "columns": [
            { "title": "1" },
            { "title": "2" },
          { "title": "3" },
          { "title": "4" },
          { "title": "5" },
          { "title": "6" },
          { "title": "7" },
          { "title": "8" },
          { "title": "9" },
          { "title": "10" },


        ],
        "order": [],
        "paging": true,
        "lengthChange": false,
        "search": {
            "search": website
        }
    });
});
});
Community
  • 1
  • 1
kuis01
  • 21
  • 2
  • 1
    I don't think the size is the problem. http://jsfiddle.net/filipetedim/qL4vta9k/ If you see, I can create 100k positions in that JavaScript array. Unique ones. – Ted Jul 15 '15 at 16:59
  • Your first code doesn't have a comma after the 2nd element. Check your extension's code with some js-linter, maybe there are more typos. – wOxxOm Jul 15 '15 at 17:22
  • MDN declares the value of the length property of an array as "The value of the length property is an integer with a positive sign and a value less than 2 to the 32nd power (232)" which I hope has some correlation to the max capactiy of an array. – mccainz Jul 15 '15 at 17:23
  • @kuis01, was the issue resolved by fixing the comma typo? – wOxxOm Jul 27 '15 at 12:33

0 Answers0