How to find page/dom load completed

Hi,

We are working on an Open Source extension: Digital Assistant Client

We have a script which invokes clicks on web pages. We record a sequence of clicks as a ‘flow’ or ‘task’. i.e. After the first click is invoked, we wait 5 s for the page to load and then invoke the 2nd click.

setTimeout(function(){UDAPluginSDK.showhtml();}, 5000);

Now, instead of waiting for 5s, we want to explore if we can invoke the 2nd click as soon as the page is loaded. We tried using “onPageLoad” but we realised that this does not work for modern single page (responsive) applications. i.e. we don’t know when the js has finished executing.

window.addEventListener(‘load’, (event) => {

setTimeout(function (){ UDAPluginSDK.modifybodyhtml(); },2000);

});

There really isn’t a universally guaranteed way. You could for example use a MutationObserver and debounce it for the trailing edge, so you get active once the modifications stop. But what if a page constantly modifies its DOM? A better strategy might be to try and find things in the DOM you’re expecting to exist when the action executes.