Linux Script to check Active URL in Firefox

Hey guys,

currently I'm struggling with a little script to check an active URL in my running Firefox.

What I'm doing:
I'm running a low VPS with about 768mb RAM and Ubuntu on it. I only installed Fluxbox + Firefox to it in order to keep the resource consumption as low as possible. I think i had success in that point. Now i would like to check an opened URL in firefox which is browsing through several videos. Sometimes it hits an Error Page cause the video might not be found etc. I set up a crontab which reboots the VPS every 15mins. This is just temporary and causes my VPS to waste a lot of time in order to wait for a reboot. It will also reboot if there is no error. Now I would like to optimize this, to check the current opened URL in firefox. If it's maybe like this blabla.com/error.php or blabla.com/start.php. If it's the first one do a quick reboot, otherwise do nothing. The script will be added as cron to run every min or so.

If you could give me a little impact on how to solve this I would very much appreciate it. Is this possible, or do I need to switch to other programming languages?

Anyways, thanks for your help! :slight_smile:

Probably the most sensible way to do this would be a script inside firefox itself. Just an HTML file you store on your own computer and open up in another tab, which runs a bit of javascript. It could be pretty low-impact that way too.

Trying to control firefox from the outside OTOH is going to be a royal pain.

Well, I don't think you are able to reboot Linux via jscript, do you? :wink:

You want to reboot the entire system? Not the browser? Oh...

Why reboot the entire system based on a failing browser? Might it be possible to check for outside connectivity with different things, like ping and such? Because controlling a browser from console is still a pain. Different worlds.

1 Like

Well, I might try to just do a crontab with killall firefox && firefox.

Why not just refresh the page, even? I had a javascript to do that until you said you needed to reboot the whole computer and I deleted it :wall:

'dest' should be the webpage you want to reset it to. /regex/ is a regular expression which matches the page it stalls at.

<html>
<body>
        <script type='text/javascript'>
                var dest="http://website/whatever.html";
                var rwindow=window.open();
                var t=1000 * 5 * 60; // 5 minutes in milliseconds

                function refresh()
                {
                        if(rwindow.location.match(/regex/))
                        {
                                rwindow.location=dest;
                        }

                        setTimeout("refresh()", t);
                }

                refresh();
        </script>
</body>
</html>
1 Like

Thank you so much! This is great! :slight_smile:

Just realized it had a bug in it. It doesn't ever set the URL in the first place.

<html>
<body>
        <script type='text/javascript'>
                var dest="http://website/whatever.html";
                var rwindow=window.open();
                var t=1000 * 5 * 60; // 5 minutes in milliseconds

                rwindow.location=dest;

                function refresh()
                {
                        if(rwindow.location.match(/regex/))
                        {
                                rwindow.location=dest;
                        }

                        setTimeout("refresh()", t);
                }

                refresh();
        </script>
</body>
</html>