How to wait say 5 seconds after user selects the tab|window to record on

35 Views Asked by At

I'm using RecordRTC for screen recording on my website.

I want to wait for 5 seconds and show a timer-like thing AFTER THE USER HAS SELECTED THE WINDOW|TAB to record the screen on.

Basically I'm interested on some browser events that will be fired when the user selects the window|tab to perform screen recording on.

Is this possible? Thx in advance.

2

There are 2 best solutions below

0
Franco Aguilera On

something like this ?

const delay = (n) => new Promise((resolve) => setTimeout(resolve, n));
await delay(5000);

console.log('something'); // will run after 5 seconds

(it has to be inside and async function)

0
Phaelax z On

You can use window.onfocus a timeout function.

window.onfocus = function() { 
  
  setTimeout(function() {
    doRecordStuff(); 
  }, 5000);
  
  
};

function doRecordStuff(){console.log('recording...');}