Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi, I want click on button at exact time, for example (11:10: 10: 122), without even a few milliseconds of error (or a maximum of 10 milliseconds)

my button 

<      document.querySelector('#btn-buy').click();       >

i wrote this code but has around(90 millisecond)error

<pre lang="Javascript"><pre>  

    var timerId;
    start = Date.now()
    execTime = new Date().setMinutes(47,59,000)

    var t=setTimeout(() => {
        count = 0
        timerId = setTimeout(() => {

            document.querySelector('#btn-buy').click();
            console.log(0);
            
        })
    }, execTime - start)


thanks

What I have tried:

i wrote this code but has around(90 millisecond)error

<pre lang="Javascript"><pre>  

    var timerId;
    start = Date.now()
    execTime = new Date().setMinutes(47,59,000)

    var t=setTimeout(() => {
        count = 0
        timerId = setTimeout(() => {

            document.querySelector('#btn-buy').click();
            console.log(0);
            
        })
    }, execTime - start)
Posted
Updated 21-Nov-20 20:33pm

1 solution

That's not going to happen on Windows. You cannot get that kind of precision on a shared system that is not a real-time O/S.

Events like that are guaranteed to happen NO SOONER THAN SCHEDULED. That does not mean exactly as scheduled.
 
Share this answer
 
v2
Comments
sara98 22-Nov-20 2:52am    
Do you think it is possible to solve this problem by writing code in UTC time?

Only I do not know how to write the code with the UTC time.
Dave Kreskowiak 22-Nov-20 12:14pm    
The timezone has nothing to with the accuracy and response of any scheduled task.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900