0
Follow
0
View

setinterval automatically clicking the page button causes the page to crash

devil780626 注册会员
2023-02-27 14:10

Depending on the code provided, the setInterval() function you use hits a button at 20-second intervals. This approach can cause the page to be clicked frequently in a short period of time, which can cause the page to crash.

To avoid this, try using the setTimeout() function. This will perform a click after a certain amount of time, and then again after a certain amount of time. This way, you can set a long interval for each click, and the page doesn't click frequently in a short period of time.

Here is sample code using the setTimeout() function:

function clickButton() {
document.getElementsByClassName("MuiIconButton-colorPrimary")[0].click();
setTimeout(clickButton, 20*1000);
}

setTimeout(clickButton, 20*1000);

In the sample code above, we define a function called clickButton() that first clicks on the button and then waits 20 seconds before calling itself again. Finally, we call clickButton() with the setTimeout() function after the page loads, so that clicking automatically starts after 20 seconds after the page loads.

Please note that no matter which method is used, great care should be taken to avoid damage to the site. Before attempting this method, it is a good idea to obtain permission from the site owner and follow the site's rules of use.

fan177 注册会员
2023-02-27 14:10

Memory leaks if you keep clicking. Do you want to keep clicking?

duoqingduoyi 注册会员
2023-02-27 14:10

the reference answer GPT ᴼ ᴾ ᴱ ᴺ ᴬ ᴵ < br / > according to your instructions, You want to periodically click the first button in the class named "MuiIconButton-colorPrimary" on the page. However, you are using the setInterval function for timed clicks, which can cause the page to freeze or crash in some cases.

There are many reasons that may cause the page to freeze or crash. For example, the timer is triggered frequently, resulting in slow page response. Or the timer is running in the background, causing page resources to be exhausted, etc.

To avoid this, you can try rewriting your instructions. For example, you can use Vue's timer feature to hit a button at a certain time:

1. Add a button click event method to the component that requires the button to be clicked:

methods: {
  handleClick() {
    document.getElementsByClassName("MuiIconButton-colorPrimary")[0].click();
  }
}

2. In the component's created life cycle, use the setInterval method to trigger the button click event:

created() {
  setInterval(this.handleClick, 20 * 1000);
}

In this way, every 20 seconds, a button click event is triggered. By using the timer function of Vue, you can better control the timer life cycle to avoid page jam or crash.

About the Author

Question Info

Publish Time
2023-02-27 14:10
Update Time
2023-02-27 14:10