To imitate user input artificially, you can utilize the dispatchEvent function (check out this informative discussion on StackOverflow regarding simulating key press events). Nevertheless, emulating a continuous keypress for an extended period might pose challenges. Instead of continuously dispatching keyboard events using setInterval, consider redesigning your code to handle the specific action triggered by pressing the Space key during page load.
setInterval(() => {
document.dispatchEvent(keyboardEvent);
}, 100);
An alternative approach would involve revising the affected code segment that relies on spacebar input without actually simulating the key down event. Additionally, sharing some portion of your script code could provide further insights.