frans
frans

Reputation: 9798

In browser environments how do I detect that all JavaScript code has terminated?

For testing purposes I want to detect the 'end' of a script, i.e. when no function is running anymore and no asynchronous tasks are on the queue.

In Node.js I can simply add an exit handler:

process.on('exit', () = {do_stuff();});

which will fire do_stuff() just before my node instance terminates.

For browser environments I know

window.addEventListener('beforeunload', {do_stuff();});

but that will fire do_stuff() only when I reload the site content and thus terminate the current 'instance' of my script.

How would I implement process.on('exit', fn) in ES6 for a browser?

Upvotes: 0

Views: 135

Answers (0)

Related Questions