I have asked a question not too long ago on how to wait for a script to be executed by cefSharp before continuing my main program and I was advised to use await browser.EvaluateScriptAsync(...)
this works fine when I am not using any EventHandler.
But say that I want to wait for the Dom to be loaded before executing my script I would use the following event handler:
window.addEventListener('DOMContentLoaded', (event) => {
console.log('DOM fully loaded and parsed');
});
What I want to do now is return true once the Dom is loaded (and return nothing before).This would theoretically allow my program to wait till the dom is loaded before the execution continues. So what I tried to do was the following :
await browser.EvaluateScriptAsync( "
function returnTrue() {
return true;
}
function waitForDom(callback) {
window.addEventListener('DOMContentLoaded', (event) => {
console.log('hi');
callback();
});
waitForDom(returnTrue);
"};
console.WriteLine("outside");
The expected output would be :
hi
outside
but what I get is :
outside
hi
This implies that my main program doesn't wait for the Dom to be loaded before continuing.
Why does this not work ?