Search code examples
javascriptgoogle-chromedelaysleep

Pause Javascript when executing it in browser console


I need to execute a Javascript in the console of Chrome with some delay. How can this be done?

The reason I need this is that as soon the focus changes from the webpage (or a certain element of the webpage) it is redrawn. Therefore I want to start the script I execute in the console with a few seconds delay so I can change the focus to the right element on the page I am working with.

Edit 1: Dinesh Padiyan.

Doesn't work for me, se screen shot:

enter image description here


Solution

  • function delay (ms){   return new Promise(resolve => setTimeout(resolve, s));  }
    

    "async" working demo on: http://zarsoft.info/software/_Test/pause_javascript/index.html