A lot of my script is contingent on information first read from a .JSON file using fetch()
and .json()
so it's asynchronous. I need to delay the execution of the rest of my script until those functions finish, without sticking the rest of my code in a huge .then()
or function block or something. I've done some searching around but I can't really find what I'm looking for.
let config;
fetch(chrome.runtime.getURL("../config.json"))
.then(response => response.json())
.then(json => config = json);
console.log(config);
// REST OF SCRIPT
It should log the config JSON object or the promise but, obviously, it only returns undefined. Any help would be greatly appreciated!