PHP Classes

PHP Browser Reload: Control a Web browser from the command line

Recommend this page to a friend!
  Info   View files Documentation   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 90 This week: 1All time: 9,925 This week: 571Up
Version License PHP version Categories
browser-reload 1.0MIT/X Consortium ...7.4Unix, GUI, Console, PHP 7
Description 

Author

This package can control a Web browser from the command line.

It provides a class as part of a PHP script that uses the xdotool program to send fake user input to a browser running on the same computer with a given window name to make it reload the currently displayed page.

Currently, it can reload browser windows using Firefox, Chrome, and Opera, among other browser types.

Innovation Award
PHP Programming Innovation award nominee
April 2022
Number 6
The best way to test a Web application is to do human testing.

Human testing means that a natural person uses a browser to access the Web application pages. It is possible to confirm that the user performs the desired actions in the application.

Sometimes it is convenient to automate the tests making the current user access the same page again. So the user would need to tell the browser to reload the current page.

This package provides a means to automate the browser reloading process by emulating the user's input to make the browser reload the current page without having a natural person interacting with the browser application.

Manuel Lemos
Picture of Engin Ypsilon
Name: Engin Ypsilon <contact>
Classes: 5 packages by
Country: Germany Germany
Age: 44
All time rank: 4206225 in Germany Germany
Week rank: 420 Up17 in Germany Germany Up
Innovation award
Innovation award
Nominee: 1x

Documentation

BroRelo - Browser Auto Refresh / Reload for Firefox, Chrome & Opera

Ubuntu 21.10 | Apache/2.4.48 | PHP 8.0.18

This package can reload windows regardless of which Browser are in them and without the need of any additional Browser-extensions for any Browser.

Currently it works with Firefox, Chrome & Opera (but it should work with all Browsers). It doesn't even needs a URL or IP to work, but a identifier in the Title <title></title> of the Page. And it also doesn't use an observer or services in order to work, it runs, when it's requested.

@install xdotool - window management

sudo apt-get install xdotool

@install browser-reload

# create directory, if not exists
mkdir -p ~/bin/browser-reload

# enter directory
cd ~/bin/browser-reload

# get browser-reload
git clone https://github.com/eypsilon/browser-reload.git

# make it executable
chmod +x ~/bin/browser-reload/browser-reload.php

To restrict the script to your local environment, set an EnvVar on your local Server and pass it to Env. For Apache2:

sudo gedit /etc/apache2/envvars
# append
export LOCAL_MACHINE_TITLE=" local-dev-many-title"

sudo gedit /etc/apache2/apache2.conf
# put
PassEnv LOCAL_MACHINE_TITLE

See config.php.example to set custom default configs and handle error occurrences.

To now make a Page (window) auto reloadable, just put the EnvVar in it's Title (or the value itself). This script searches in windownames of open windows to check if they contain the specified EnvVar. If a Window matches the criteria, the key defined in $config['trigger_key'] will get fired ("F5" | "ctrl+r").

Multiple windows with multiple Browsers at the same time are working as well - the Pages have to be active in the windows they're in (visible, top tab), and that's it.

<title>...<?= /local/ $_SERVER['LOCAL_MACHINE_TITLE'] ?? null ?></title>

Visual Studio Code

To reload Browser on save, @install vscode-run-on-save

~/.config/Code/User/settings.json

{
    "runOnSave.statusMessageTimeout": 1000,
    "runOnSave.commands": [
        {
            "match": ".*",

            // # Options
            // "command": "...browser-reload.php    Options=GoesHere",

            // output=true                          // [false | 'minimal'] :: default true
            // set_timeout=0.1                      // > 0                 :: default 0.1
            // trigger_key='ctrl%2Br'               // ['F5' | 'ctrl%2Br'] :: default 'ctrl+r'
            // srch_title='local-dev-many-title'    // (string)            :: default 'local-dev-many-title'

            // # set custom Browser names to search for. To get
            // # the Name of a window, run "xprop | grep WM_CLASS"
            // # and click the window of interest. Defaults are
            // srch_browser[]=Navigator
            // srch_browser[]=Google-chrome
            // srch_browser[]=Opera

            // # Additional titles to search for, on error for example
            // # see config.php.example for more infos
            // match_title[]='Mozilla Firefox'

            // # Add regexe, see config.php.example for more infos
            // regex_title[]='~localhost.loc~'

            // # the file, that has triggered the reload
            // filename=${fileBasename}
            // extension=${fileExtname}
            // file=${file}
            // dir=${fileDirname}

            "command": "~/bin/browser-reload/browser-reload.php",
            "runIn": "backend",
            "runningStatusMessage": "BrowserReload started ${fileBasename}",
            "finishStatusMessage": "BrowserReload done, ${fileBasename}"
        }
    ]
}

Enable / Disable via cmd ctrl+shift+p

Run On Save: Enable
Run On Save: Disable

Check response output: ctrl+k + ctrl+h > Output > "Run on Save"

Custom Config

Use custom configs to overwrite default configs. Set a list of strings to handle errors on your Page.

Regular Expressions

Set regular expressions to handle error pages. See 'config.php.example' for more infos.

Add Aliases (optional)

~$ sudo gedit ~/.bash_aliases

alias BrowserReload='~/bin/browser-reload/browser-reload.php'
alias BrowserReloadQuiet='~/bin/browser-reload/browser-reload.php output=false'

~$ source ~/.bash_aliases

with Aliases in place, we can reload open windows from the terminal with

BrowserReload

  Files folder image Files  
File Role Description
Plain text file browser-reload.php Class Class source
Accessible without login Plain text file config.php.example Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:90
This week:1
All time:9,925
This week:571Up