Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

242
Vistas
Workaround for GET XMLHttpRequest (local request) size limits

Problem

Whilst developing a chrome extension I encountered a problem where I try to retrieve large JSON file (~1GB) using XMLHttpRequest GET request. The file is located on my local machine and I retrieve the download link using chrome.runtime.getURL('data.json') from a content script.

The error I am getting is

Uncaught SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at xhr.onreadystatechange (<anonymous>:11:23)
    at XMLHttpRequest.<anonymous>

I assumed it is because the JSON file is too large and therefore, it is not possible to download it in one go (please correct me if this wouldn't be the case). Is there any workaround for this size limitation?

Additional info

I generate the JSON file from a python script, thus, it is completely possible to choose a different format (some binary format maybe) if necessary.

Furthermore, I cannot use any API provided for chrome extensions since the script I am actually calling the XMLHttpRequest from is not a content script but an appended script to the body of the website.

Here is a minimal code for reproduction (don't forget to configure the content_security_policy in the manifest to enable inline script execution).

// Content script

function init() {

    let script = document.createElement("script");
    script.appendChild(document.createTextNode(__magic.toString() + "; __magic('" + chrome.runtime.getURL('data.json') + "');"));
    script.id = "__magic";
    document.body.appendChild(script);
}

function __magic(url) {
    var db;
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = () => { 
        if (xhr.readyState === 4) {
            db = JSON.parse(xhr.response);
            window.setInterval(check, 10);
        }
    };
    xhr.open("GET", url, true);
    xhr.send();
}

init();

Edit


I forgot to say that I was successful in loading the big JSON file in python, thus, I think it is safe to assume that the JSON file is not corrupted.

Furthermore, the JSON file is storing a graph structure - I choose following layout for the json file

{
 "node1": {
   "children": ["node2", "node3"],
   "foo": 15
 },
 "node2": {
   "children": ["node15", "node1"],
   "foo": 90
 },
 ...
}

I bet there is a more efficient way of storing a graph structure rather than using JSON, however, so far I could not find any that would be compatible with javascript.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

  1. save the response in a new file and confront the size with the original file.
  2. try with xhr.responseType = "json" and no parse the response (if you can)
  3. try to split the local file into smaller chunks and make several asyncromous xmlhttprequest\fetch requests (Promise.all) and then joint the responses into your big final json file.
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda