3 Replies Latest reply on Aug 12, 2013 2:14 PM by jpierson

    Webviewer and no internet work around



      Webviewer and no internet work around


           Hey everyone!


           i have a some scripts in my database that does a "callHome" type thing that pulls xml data into a hidden webviewer so i can do some parsing. my problem is that if theres no internet connection or user has a extremely slow connection i would like the script to abort, my question is how can i let my script know that if there is no internet connection to exit the script so the users can continue on?

           any insight would be very much appreciated :)

        • 1. Re: Webviewer and no internet work around

          Hello. This is an old post but I thought I would respond in case anyone else is looking for a solution.


          I think the lack of responses is due to the way your title is worded. Obviously if you have no internet connection then there is no work around for using the web viewer. At least not for web based sources.


          However, there are ways to do what you want which is to detect whether or not you have a usable internet connection before proceeding with scripts involving web scraping, syncing, etc.


          What I have done recently is to use a web viewer (either the same one or a separate one) and simply have it go to www.google.com or any similar simple web page. (For commercial use you should probably use your own web page.)


          You want to use the Set Web Viewer script step just prior to your test, setting it to google or the url of your test page.


          Then use the Get ( LayoutObjectAttribute ) with the "content" attribute specified to set a variable such as $Content. When I really want to try to get the content I will use a Pause/Continue script step set at about 3 or 4 seconds that is placed just after the Set Web Viewer step. You could use a very short or no pause which will insure that the $Content variable will only populate if you have a fairly fast connection. You would need to experiment with the pause duration to achieve your desired result of rejecting a slower connection.


          Once you have your $Content variable set you just need to use the PatternCount Function to look for some text (such as "Google") that you know will be present if the page loaded successfully and not present if the page did not load. Note that $Content may not be empty even if the page did not load. The browser will often load some kind of 404 not found page or something similar.


          In the "Google" example you might have IF PatternCount ( $Content ; "Google" ) < 1 Halt Script or Exit Script, Show Custom Dialog or whatever.


          So to use your own page all you would really need is a single <p> tag with the word "Success" or even just the number 1. If PatternCount finds it you have a connection, if not then you don't.  However, such a simple page may load quite quickly even with a relatively poor internet connection. You may need to add some complexity just to slow it down allowing you to only populate $Content when you have a reasonably fast internet connection.


          Again this will take some trial and error. It is not an exact science since there are other variable factors besides the speed of your connection that will determine how quickly a page will load.


          I have heard it suggested that you can run a speed test in the web viewer such as www.speedtest.net. I have not tried this but these usually take a while to run even on a desktop. While it might allow you to actually determine the connection speed and continue or abort accordingly it might cause a 30 second or more delay each time your sync is run and defeat the whole purpose of not wasting the users time.


          • 2. Re: Webviewer and no internet work around

                 I believe that you are referring to GetLayoutObjectAttribute (  ), not Get ( layoutobjectattribute ).

                 And wouldn't Not Is Empty ( $Content ) also work as the test to see if the web page loaded in the viewer or not?

            • 3. Re: Webviewer and no internet work around

                   Hi PhilModjunk.

                   You are absolutely correct, it should look something like:  GetLayoutObjectAttribute ( "WV1" ; "content" ). Thanks for the clarification.

                   I tested using a Windows 8 machine with IE 10 set as the default browser and running FM Pro 12 Advanced. I found that with my internet connection disabled running the Set Web Viewer script step with action set to "Reset" would leave the Web Viewer loaded with a sort of Microsoft message about troubleshooting your connection, etc.,  that is HTML based.

                   So the GetLayoutObjectAttribute ( ) Function still returns HTML content to the $Content variable. At least on Windows with IE 10 as the default browser, $Content cannot be assumed to be empty even when the desired page did not load.

                   This may not be the case with Safari on iOS but since I had already encountered this situation I decided it was better to check for expected content , i.e. "Google" in my example than to rely on the web viewer having no content at all.

                   There is a risk relying on a third party for this sort of thing since that content can be changed at any time and they will not feel obligated to inform you surprise. But for the forseeable future I think the word Google will be found somewhere in the HTML of the Google search home page.

                   A more elegant solution would be to create your own static page just for this purpose. I'm not sure but I think if you have enough users constantly pinging Google without actually proceeding to search for something and viewing ads Google might get upset.