How to Force a Firefox Page Refresh from Linux Console

Can I force a firefox page refresh from linux console

You can use xdotool for automation. Install on Ubuntu with

sudo aptitude install xdotool

Then you can search for windows and send keys or mouse events, see man xdotool for the full documentation. I use following script on Ubuntu 10.04 LTS during development:

WID=`xdotool search --name "Mozilla Firefox" | head -1`
xdotool windowactivate $WID
xdotool key F5

See also the xdotool project site
and my full blog post.

Firefox refresh current tab from command-line

Here's an updated version of @geekQ's script that will return focus to the previous program (however, the firefox window will still be pulled to the top).

#!/bin/bash

CURRENT_WID=$(xdotool getwindowfocus)

WID=$(xdotool search --name "Mozilla Firefox")
xdotool windowactivate $WID
xdotool key F5

xdotool windowactivate $CURRENT_WID

Automatic web-page refresh using xdotool - not sending key after window focus

After trying several different approaches to get xdotool to work correctly, I'm inclined to believe that xdotool itself is the issue. Here is what I tried, none worked.

  • Running the command (and variations - removing/adding args) from Terminal.
  • Running the command (and variations - removing/adding args) from a SH script.
  • Changing between F5 and ctrl+r keys, as they should both refresh a Firefox page.
  • Trying other parameters, such as:
    • --window to set the window the keys are to be sent to.
    • --delay to add a delay before the key is sent, after the window is focused.
    • Adding a sleep before the key is sent, after the window is focused.

I also tried these commands in a script, as the frontpage for xdotool recommends, although it states this is the "older" version, as it is separated into multiple commands. The "new" version was the version I was trying to execute before and is a single command (see question).

WID=`xdotool search "Firefox Page Title"`
xdotool windowactivate --sync $WID
xdotool key --clearmodifiers ctrl+r

All of the above attempts ALWAYS correctly focused to the window I wanted, but it does not send the key whether it was F5 or ctrl+r.

However, the following worked correctly:

xdotool selectwindow key ctrl+r

OR

xdotool selectwindow key F5

The selectwindow command, when executed, turns your cursor into a rectangular selection tool at which point you can select the window you want to be focused and, in this case, what window to send either the ctrl+r or F5 key to. Unfortunately, this is not what I was looking for, as it requires user input to work correctly.

Final Solution:

My solution (since I was attempting to use xdotool to constantly refresh a web-page) was to use the ReloadEvery Firefox add-on, which refreshes any page you set it on in any time interval you choose. It is intended to be a replica of the Opera browser's built-in automatic page refresh feature, and thus far, it works well.

For those of you who use Chrome and are looking for a similar solution, there are plenty of add-ons available for you too. https://chrome.google.com/webstore/search/auto%20refresh

refresh firefox from .bat file/ command

I was just messing around and came up with this half-working solution that might help a little. Create a file called something like refresh.vbs and paste this in:

Set WshShell = WScript.CreateObject("WScript.Shell") 
WshShell.AppActivate("Google Chrome")
WScript.Sleep 500
WshShell.SendKeys "{TAB}"
WScript.Sleep 100
WshShell.SendKeys "{F5}"

I could only test it with Chrome. The script activates Chrome, sends a tab, and then sends F5 to refresh. It works when I have Chrome up showing one web page, but not when there are multiple web tabs open (because AppActivate activates the Window, but does not give focus to anything).

Maybe it works better with Firefox. There's probably some way to enumerate the tabs in a browser and activate it in vbs, but I don't know it.

If you spawn the browser within the vbs (see WshShell.Run, and the example in the SendKeys documentation), you can get the process number and send messages directly to that Window instead of relying on the app title.

You can invoke the .vbs from within a batch file if you need to:

@echo off
refresh.vbs

How do I make Firefox auto-refresh on file change?

Live.js

From the website:

How?
Just include Live.js and it will monitor the current page including local CSS and Javascript by sending consecutive HEAD requests to the server. Changes to CSS will be applied dynamically and HTML or Javascript changes will reload the page. Try it!

Where?
Live.js works in Firefox, Chrome, Safari, Opera and IE6+ until proven otherwise. Live.js is independent of the development framework or language you use, whether it be Ruby, Handcraft, Python, Django, NET, Java, Php, Drupal, Joomla or what-have-you.

It has the huge benefit of working with IETester, dynamically refreshing each open IE tab.

Try it out by adding the following to your <head>

<script type="text/javascript" src="http://livejs.com/live.js"></script>

Refresh page when resize using Firefox

Two things:

1.This is probably what you're looking for

    <script>
var t=0,resizing=false;
function _reload()
{
resizing=false;
window.location.reload(true);
}
window.addEventListener('resize',function(){
if(!resizing){
resizing=true;
t=setTimeout(_reload, 2000);
}
});
</script>

  1. before using this, can you make sure that in your chart.js instance you are using the responsive:true parameter? Also you will probably need to use maintainAspectRatio: true parameter as well.

Refresh a page automatically from the Browser console

You can refresh a page from within the browser console by running the following command:

location.reload()

If the website you are on has jQuery loaded you will be able to run jQuery commands.

If the website does not have jQuery loaded you can use the following bookmark to inject jQuery into the page:

javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.3.2",function($,L){(function(){var d=document.createElement("div"),c=document.getElementsByTagName("body")[0],e=false,g="";d.style.position="fixed";d.style.height="32px";d.style.width="220px";d.style.marginLeft="-110px";d.style.top="0";d.style.left="50%";d.style.padding="5px 10px";d.style.zIndex=1001;d.style.fontSize="12px";d.style.color="#222";d.style.backgroundColor="#f99";if(typeof jQuery!="undefined"){g="This page already using jQuery v"+jQuery.fn.jquery;return f()}else{if(typeof $=="function"){e=true}}function a(i,k){var h=document.createElement("script");h.src=i;var j=document.getElementsByTagName("head")[0],b=false;h.onload=h.onreadystatechange=function(){if(!b&&(!this.readyState||this.readyState=="loaded"||this.readyState=="complete")){b=true;k();h.onload=h.onreadystatechange=null;j.removeChild(h)}};j.appendChild(h)}a("http://code.jquery.com/jquery.min.js",function(){if(typeof jQuery=="undefined"){g="Sorry, but jQuery wasn't able to load"}else{g="This page is now jQuerified with v"+jQuery.fn.jquery;if(e){g+=" and noConflict(). Use $jq(), not $()."}}return f()});function f(){d.innerHTML=g;c.appendChild(d);window.setTimeout(function(){if(typeof jQuery=="undefined"){c.removeChild(d)}else{jQuery(d).fadeOut("slow",function(){jQuery(this).remove()});if(e){$jq=jQuery.noConflict()}}},2500)}})();});

Firefox add-on development: automatically reload add-on after code is changed

Mozilla provides a command line tool called web-ext that allows you to run your extension in Firefox and reload automatically your code when the source files are modified.
The tool has many useful options that you can use to suit your needs, so I would recommend checking out the documentation page on MDN.

To get started quickly:

npm install --global web-ext
cd /path/to/your/webextension
web-ext run

Refresh favicon in bookmarks (Firefox)

There is a solution that works on every browser:

  • go to www.yourwebsiteurl.com/favicon.ico (works for localhost as well)

  • force refresh (Ctrl+F5 for most browsers, or manually)

  • restart the browser



Related Topics



Leave a reply



Submit