-1

I have 2 scripts that use 2 websites and communicate witch each-other. Basically: Website 1, web1 script, website 2, web2 script, and they go in loop like this: Web1 script> waits for new content on page1> sends it to website 2(changes website through window.location.href = website 2) And then after website 2 finishes job it goes back to website 1. This is how my script SHOULD work, but i have a few problems:

I am using Tampermonkey with Chrome. Every time my connection goes down, chrome changes my current website page to some custom page with no connection available error. This stops my script and it can't go back even when my internet's on again (Cause i cant @include this custom web page so i cant make script to go back to former webpage..) This script should work whole day without human interaction but it cant thanks to random 2-3 sec downtimes...

Is there a way to stop chrome from doing so OR make greasemonkey to work on custom chrome error pages OR eventually if firefox is capable of this?

I also made simple interval functin to resume my script if something's wrong and page doesn't refresh for too long, it goes like this:

function watchdog()
{    
window.setInterval(function(){console.log('woof'); ninja_t('woof');set_number = 9; localStorage.setItem('set_number',9);set(set_number);},60000);
}

Will this function work if there's some SyntaxError? I mean do setInterval functions still work after syntax errors in other functions?

user2654072
  • 145
  • 1
  • 9
  • Pretty unclear, i don't even know what's your problem. Can you post code, and explain exactly what the point ? – OlivierH Nov 13 '13 at 08:48
  • Sorry @OlivierH I edited my question. I hope now you will get what i meant. If there's still something unclear tell me. – user2654072 Nov 13 '13 at 14:10
  • Why would you get SyntaxError ? The only you can have is executing a `window.location = 'your_url'` with no internet connection available. I answer. – OlivierH Nov 13 '13 at 14:14

1 Answers1

0

If i understand well your problem, you want your script to pause if there's no internet connection available, instead of making a window.location and so crashing.

Read this to see how to check if internet connection is ok with javascript. You can use setTimeout function to pause your script, waiting for internet connection to go back.

Community
  • 1
  • 1
OlivierH
  • 3,875
  • 1
  • 19
  • 32
  • Thank You It's almost what i needed! Sadly when i added that just a sec ago i saw that one of the sites use And site is reloading anyway redirecting me to that custom "no connection" page of chrome... I think i will try to adapt script to firefox and greasemonkey, maybe that will help to preserve script. Thank You for Your help and for understanding my awful English :) – user2654072 Nov 13 '13 at 15:20
  • You can also detect a redirection with `beforeunload` event : `window.onbeforeunload = function(){...}`. With that you can catch refresh, test for internet connection and if off cancel it (return false in this function). – OlivierH Nov 13 '13 at 15:28
  • You can also remove `` tag – OlivierH Nov 13 '13 at 15:31