How to catch status 503 in tampermonkey

后端 未结 3 491
粉色の甜心
粉色の甜心 2021-01-13 15:23

I have a userscript that refreshes the page every second, but sometimes the website it\'s trying to refresh runs into the status 503 error, and that stops the script from ru

3条回答
  •  爱一瞬间的悲伤
    2021-01-13 16:01

    Simple solution I could think of is to move the actual webpage that need to be refreshed every second to another frame or some HTML container and using your user script you could refresh or reload that container with the HTML page you want to refresh.

    Unless you are making a http request to load webpage from your script it may not be possible to handle the http errors (I might be wrong!). Your user script should be at a superset level where it will have control or scope even after any 503 or any similar HTTP errors.

    You could use Page state change events to ensure or to check to refresh the page in the frame/container has loaded or not to avoid reloading the webpage before it loads. Unless if you want to reload irrespective of webpage successfully loaded or not.

    Hope this helps..

提交回复
热议问题