简体   繁体   中英

await is only valid in async functions and the top level bodies of modules

trying to make a chrome extension that scrapes a website but it always scapes it before the content is fully loaded (tried after document read thing in manifest.json)

everytime that is getting called I am getting:

await is only valid in async functions and the top level bodies of modules
const sleepz = (ms = 0) => {
    return new Promise(r => setTimeout(r, ms));
};

const finsh_minting_shit = async(profile,user_id_now) => {
  console.log("das huhn hat ein ei gelegt");
  await sleepz(4000);
  console.log("RuehrEi")
});

window.onload = function() {
  finsh_minting_shit(profile,user_id_now);
}

also tried:

await finsh_minting_shit(profile,user_id_now);
const sleepz = (ms = 0) => {
    return new Promise(r => setTimeout(r, ms));
};

const finsh_minting_shit = async(profile,user_id_now) => {
  console.log("das huhn hat ein ei gelegt");
  console.log("RuehrEi")
});

window.onload = function() {
  await sleepz(4000);
  finsh_minting_shit(profile,user_id_now);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM