I searched everywhere a simple example for loop a event whiteout the processor up to 70%. I don't find the awsner so i need help. I just need to everytime the page refresh it do the code.
Here the code:
page.once('load', async () => {
console.log("Page loaded!")
// Example of code to execute when the page reload
const searchBtn = await login.$x("//button[@id='btnEnter']");
await searchBtn[0].click();
});
You need code which executes everytime the page was loaded. You can achieve that by calling
function onLoadHandler() {
/**code goes here ***/
}
page.on('load', onLoadHandler)
You do not have to loop over this. Your onLoadHandler function will be executed everytime this particular page is reloaded.
What you did is to call page.once('load', onLoadHandler). This listens to the 'load' event once and then the handler removes it selve, it does it "once".
So probably if you looped the function page.once()(doing it 10000 times a sec) using a while loop or something your processor would ofc reach 70% usage .. Whenever your processor goes crazy like this, your code is suspected to be way to ressource heavy. In general that should not happen when running normal app without handling 10k requests per second or something.
Feel free to leave a comment.