0

I have a browser extension that sends many requests to a server. I would like to measure how long each request takes. I can use console.log to output it but that makes getting statistics very difficult.

function loadXMLDoc() {  
    var xhttp = new XMLHttpRequest(); 
    var ping = new Date;
    xhttp.open("GET", "http://cors-anywhere.herokuapp.com/blank.org/", false);
    xhttp.setRequestHeader('Cache-Control', 'no-cache');
    xhttp.send();
    if(xhttp.status == 200) {
             ping = new Date - ping;
             console.log('Ping ' + ping + 'ms');
    }
  }

Is it possible to write ping above to a text file like this?

window.requestFileSystem =window.requestFileSystem || window.webkitRequestFileSystem;

window.requestFileSystem(window.PERSISTENT, 0, gotFS, fail);

function gotFS(fileSystem) {
    console.log("gotFS is called" + fileSystem);
    fileSystem.root.getFile("/data/logFile12302021", {create: true}, gotFileEntry, fail);
}

function gotFileEntry(fileEntry) {
    console.log("gotFileEntry:" + fileEntry);
    fileEntry.file(gotFile, fail);
}

function gotFile(file){
    console.log("gotFile");
    //readBinaryString(file);
    readArrayBuffer(file);
}
function fail(){
    console.log("log file creating failed");
}

However I found window.requestFileSytem is deprecated, and I also got window.requestFileSystem is not a function error.

Is there any other way to create and write a text file using JS inside browser extension? I'm using Edge/Chrome.

Daolin
  • 614
  • 1
  • 14
  • 38

0 Answers0