Need a quick help - ExecuteScript is not Working ,unable to execute javascript!

Unable to convert csv File into a HTML file using javascript code using executescript_sandbox

ERROR I got is
[error]
Line 31: document is not defined

command : executescript_sandbox
Target:
document.getElementById(“file-input”).addEventListener(“change”, function(event) {
var file = event.target.files[0];
var reader = new FileReader();

reader.onload = function(event) {
  var csvContent = event.target.result;
  processCSVFile(csvContent);
};

reader.readAsText('./reports.csv', 'utf-8');

});

function processCSVFile(csvContent) {
var rows = csvContent.split(“\n”);
var htmlTable = “

”;
htmlTable += “

Report Status

”;

for (var i = 0; i < rows.length; i++) {
  var row = rows[i].split(",");
  htmlTable += "<tr>";

  for (var j = 0; j < row.length; j++) {
    htmlTable += "<td>" + row[j] + "</td>";
  }

  htmlTable += "</tr>";
}

htmlTable += "</table>";

// Do something with the HTML table
console.log(htmlTable);

}
value: javascript

executescript**_sandbox** can not access anything on the website. Use executescript instead.

1 Like

Hi ,execute script is not working too. Please provide working examples to execute javascript and html program.Thank You!!
Line 36: Error in executeScript code: require is not defined

var fs = require(“fs”);

fs.readFile(“./reports.csv”, ‘utf8’, function(err, csvContent) {

if (err) {

    console.error(err);

    return;

}




var rows = csvContent.split("\n");

var htmlTable = "<table>";

htmlTable += "<h3> Report Status </h3>"

for (var i = 0; i < rows.length; i++) {

    var row = rows[i].split(",");

    htmlTable += "<tr>";




    for (var j = 0; j < row.length; j++) {

        htmlTable += "<td>" + row[j] + "</td>";

    }




    htmlTable += "</tr>";

}




htmlTable += "</table>";




saveFile("report.html", htmlTable);

});

function saveFile(filename, data) {

fs.writeFile(filename, data, function(err) {

    if (err) {

        console.error(err);

    } else {

        console.log(filename + " saved successfully.");

    }

});

}