Promise not returning value of request
I have this promise: function getAPI(token) { return new Promise((resolve, reject) => { console.log("Request API"); GM_xmlhttpRequest({ method: "GET", url: "URL"+token, onload: function(response) { console.log(response.responseText); if( response.responseText == "NOT_ANSWER" || response.responseText.indexOf("ERRO") > -1 ){ console.log(response.responseText + " - Calling Myself in 5 Seconds"); setTimeout(function(){ getAPI(token); },5000); } else{ console.log('Call API - Giving Result'); resolve(response.responseText.split("_")[1]); } } }); }); } I call it inside of itself when the answer is