0

I have an user script that runs a bunch of code and then reloads the page after 1 second. Sometimes though, the page fails to load resource, and the user script stops running. When that happens, the page stops reloading. It happens like once every few hours for some reason.

The link is still the same exact link, but the user scripts stops running, and stops reloading the page when that happens. What can I do to fix this, and keep reloading the page even after it fails to load resource?

When I go to inspect the page I see this error in the console logs:

Failed to load resource: the server responded with a status of 503 (Service Unavailable)
frosty
  • 2,559
  • 8
  • 37
  • 73
  • try/catch the error inside the script so it does not lock and end. So if the resource is not found, either provide a default resource to use instead, or skip all code that manipulates that resource. – Shilly Sep 18 '18 at 14:52
  • @shilly Can you provide an example code please? – frosty Sep 18 '18 at 14:54
  • I posted an example using `fetch()`. Question though: wouldn't it be more efficient to just not refresh the page and loop fetching the resource instead? – Shilly Sep 18 '18 at 15:03
  • So I have var html = document.getElementsByTagName('html')[0]; var text = html.innerHTML; if (text) { //execute code } – frosty Sep 18 '18 at 15:10
  • @shilly and else { //refresh the page } – frosty Sep 18 '18 at 15:10
  • That might work. Can you just show your code, since i dont understand what getElements or innerHTML has to do with fetching a resource that return 503. Or do you mean that the page itsself returns a 503? And hence, there's no html + script to run to begin with? – Shilly Sep 18 '18 at 15:12
  • @Shilly Okay, so first of all, what exactly is a resource? Isn't that like the content of the page or something? So the userscript executes with match, and then I get the content of the page with document.getElement, and html.innerHTML – frosty Sep 18 '18 at 15:16
  • I thought you meant that your script was loading a second file/resource that returns 503. But its the script itsself that can't be found right? In that case, you can't fix this with javascript, sicne there won't be any javascript to execute when you hit 503. You'll need some external program to load your page. – Shilly Sep 18 '18 at 15:18
  • @shilly I also have multiple GM_xmlhttpRequest inside the code, if that's what you're asking. I don't know what is returning the 503 error. It doesn't say in console logs when I inspect the page. So what exactly is a resource? Is that the website page, or what? Or is that my userscript code? – frosty Sep 18 '18 at 15:21
  • @Shilly I also have audio in the code, like: var audio1 = new Audio("http://www.pacdv.com/sounds/interface_sound_effects/beep-3.wav"); – frosty Sep 18 '18 at 15:23
  • 1
    Can you please just post your code? It's very hard to see all the things working on your page with just a description of what there is instead of the code. WIth some code, we would be able to actually run that code and see where the issues are concerning the structure. Then it'll be way clearer to us which request return 503. THe fix might be as small as wrapping a certain line in an if-clause, but we won't know if we keep guessing. – Shilly Sep 19 '18 at 07:19

0 Answers0