What are the time limits for repeating setInterval?

  • 0
    Hello everyone. There is a code that automates filling and submitting a form on the site. I'm not a coder, I collected pieces from various forums, and this is what happened:

    setInterval(() => {
      const field1 = document.querySelector('[name="название"]'); 
      const field2 = document.querySelector('[name="название"]'); 
      const field3 = document.querySelector('[name="название"]');
      const btn = document.querySelector("..........."); 
      field1.value = "значение";
      field2.value = "значение";
      field3.value = "значение"
    }, 1000);

    That is, the button will be pressed every second. Question: if I specify 1 instead of 1000, will the button be pressed every 0.001 second? And if I specify 0.1, it will be pressed every 0.0001 second, what? Is there any limit at all?
    Will the browser be able to make requests with such a frequency with such a high speed?
    Thank you.
    JavaScript Genevieve Kim, Feb 15, 2020

  • 1 Answers
  • 0
    setInterval doesn't run your code. He only sets a timer, and after a specified period of time informs the browser that he needs to execute this code. But this does not guarantee that your code will be executed right there. The task will be queued. And the browser will take it out of the queue when it can. All other tasks will be queued in the same way, even if the previous ones have not yet been completed.

    https: //medium.com/devschacht/javascript-eventloop ...

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!