Minh
Minh

Reputation: 135

Run firefox addons from command-line

I am working 508 accessible standard for a website. There are a Firefox plugin to help check on each page a website WAVE addons
I am having a crawler that walk throught all pages of the website.
Now i want to combine WAVE addons + my crawler to check website as 508 accessibility compliance automatically.

My question is how to run Firefox addons with a specific URL from command line?

Thanks for your help,
Minh

Upvotes: 4

Views: 4739

Answers (2)

F. Hauri  - Give Up GitHub
F. Hauri - Give Up GitHub

Reputation: 70722

Edit 2023, workaround Block toplevel data: see further!

Run firefox extras from command-line.

You could do many complex thing from comand line as running inline javascript (I've posted a Color RGB shower using firefox 'data:text/html.. under Another approach, at bottom of answer).

Maybe this could help you:

$ firefox 'data:text/html;charset=ISO-8859-1,
<html>
<head>
<title>TEST Demo</title>
</head>
<body>
<h3 id="title">Test demo</h3>
<script language="javascript">
window.open("http://perso.f-hauri.ch/~felix/svg/dustin_w_Clock_autonom.svg","clock","toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=400,height=400,top=36,left=700");                                     
window.open("https://stackexchange.com/users/flair/1965184.png","netrate","toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=208,height=58,top=36,left=490");
var s=10;                                                                 
function cntdwn()                                          
{                                                                 
  document.getElementById("title").innerHTML="Test demo: "+s;s=s-1;
  if (0 > s)                                                      
  {                                                                      
    window.location="https://stackoverflow.com/a/13013464/1765658";
  }                                                                      
  else window.setTimeout(cntdwn,1000);
  };                                        
  window.onload=cntdwn;
 </script>
 </body>'

This could be written:

$ firefox 'data:text/html;charset=ISO-8859-1,<html><body><h3 id="title"></h3>'"$(
    cat <<eof
        <script language="javascript">
        var s=10;
        function cntdwn() {
            document.getElementById("title").innerHTML="Test demo: "+s;s=s-1;
            if (0 > s) {
                window.location="https://stackoverflow.com/a/13013464/1765658";
            }
            else window.setTimeout(cntdwn,1000);
        };
        window.onload=cntdwn;
        window.open("http://perso.f-hauri.ch/~felix/svg/dustin_w_Clock_autonom.svg","clock","toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=400,height=400,top=36,left=700");                                     
        window.open("https://stackexchange.com/users/flair/1965184.png","netrate","toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=208,height=58,top=36,left=490");
        </script>  </body>
eof
)"

Or even:

$ firefox 'data:text/html;charset=ISO-8859-1;base64,PGh0bWw+PGhlYWQ+PHRpdGxlPlRF
U1QgRGVtbzwvdGl0bGU+PC9oZWFkPjxib2R5PjxoMyBpZD0idGl0bGUiPlRlc3QgZGVtbzwvaDM+PHNj
cmlwdCBsYW5ndWFnZT0iamF2YXNjcmlwdCI+d2luZG93Lm9wZW4oImh0dHA6Ly9wZXJzby5mLWhhdXJp
LmNoL35mZWxpeC9zdmcvZHVzdGluX3dfQ2xvY2tfYXV0b25vbS5zdmciLCJjbG9jayIsInRvb2xiYXI9
MCxsb2NhdGlvbj0wLHN0YXR1cz0wLG1lbnViYXI9MCxzY3JvbGxiYXJzPTEscmVzaXphYmxlPTEsd2lk
dGg9NDAwLGhlaWdodD00MDAsdG9wPTM2LGxlZnQ9NzAwIik7d2luZG93Lm9wZW4oImh0dHBzOi8vc3Rh
Y2tleGNoYW5nZS5jb20vdXNlcnMvZmxhaXIvMTk2NTE4NC5wbmciLCJuZXRyYXRlIiwidG9vbGJhcj0w
LGxvY2F0aW9uPTAsc3RhdHVzPTAsbWVudWJhcj0wLHNjcm9sbGJhcnM9MCxyZXNpemFibGU9MCx3aWR0
aD0yMDgsaGVpZ2h0PTU4LHRvcD0zNixsZWZ0PTQ5MCIpO3ZhciBzPTEwO2Z1bmN0aW9uIGNudGR3bigp
e2RvY3VtZW50LmdldEVsZW1lbnRCeUlkKCJ0aXRsZSIpLmlubmVySFRNTD0iVGVzdCBkZW1vOiAiK3M7
cz1zLTE7aWYgKDAgPiBzKXt3aW5kb3cubG9jYXRpb249Imh0dHBzOi8vc3RhY2tvdmVyZmxvdy5jb20v
YS8xMzAxMzQ2NC8xNzY1NjU4Ijt9ZWxzZSB3aW5kb3cuc2V0VGltZW91dChjbnRkd24sMTAwMCk7fTt3
aW5kb3cub25sb2FkPWNudGR3bjs8L3NjcmlwdD48L2JvZHk+'

(Care to split Base64 by multiple of 4 chars!)

This work same with chromium and, I believe, near every browser...

Edit 2023: workaround Block toplevel data:

For security reason, from version 57, firefox doesn't no open this kind of links anymore. Running this command line will just open a new window and put the entire data:... link into location field.

I will have to hit in the new firefox window:

  • Ctrl+l for focusing location field,
  • Return for forcing firefox to open data:... link.

Then

  • Alt+p for activating preferences button, and finally
  • p to tell firefox: we are ok to open popups.

For doing this automatically, I use xdotool (and xwininfo, under ).

( Of course, I could go to about:config, then set security.data_uri.block_toplevel_data_uri_navigations to false, but I think this is a bad idea! )

#!/bin/bash

title='Inline html demos ( bash + javascript )'
targetUrl='https://stackoverflow.com/a/13013464/1765658'

declare -A urls='(
  [clock]="http://perso.f-hauri.ch/~felix/svg/dustin_w_Clock_autonom.svg"
  [flair]="https://stackexchange.com/users/flair/1965184.png"
)'
declare -A sizes='(  # " Left, Top, Width, Height, Resizeable (bool) "
  [clock]="               700,  36,   400,    400,          1 "
  [flair]="               490,  36,   208,     58,          0 "
)'
renderHtml() {
    cat <<-eof
        <html>        
          <body><h3>$title</h3><div id="title">[ . . . ]</div>
            <script type='text/javascript'>//<![CDATA[ 
            var s=10;
            function cntdwn() {
                document.getElementById("title").innerHTML="Countdown: "+s;
                s=s-1;
                if (0 > s) {
                  window.location="$targetUrl"
                }
                else window.setTimeout(cntdwn,1000);
            };
            function popwin(url,name,x, y, w, h, r) {
               var optns=["toolbar=0", "location=0", "status=0", "menubar=0",
                  "scrollbars=" + r, "resizable=" + r, "width=" + w, "height=" +
                  h, "top=" + y, "left=" + x].join(",");
               window.open(url,name,optns);
            };
            window.onload=cntdwn;
eof
    for topop in "${!urls[@]}"; do
        printf 'popwin("%s","%s",%s);\n' "${urls[$topop]}" \
            "$topop" "${sizes[$topop]}"
    done
    echo $'\n//]]>\n  </script>\n</body>'
}
firefox 'data:text/html;base64,'"$(renderHtml|base64|tr -d \\n)" &

# Workaround 'security.data_uri.block_toplevel_data_uri_navigations=true'
exec {dummySleep}<> <(:)
for ((i=2500; i--; 1)); do   # Wait 5 secondes for new Firefox window.
    { read -r _; read -r _{,,,} wintitl
    } < <(xwininfo -id "$(xdotool getactivewindow)")
    case ${wintitl//\"} in Firefox*|Mozilla\ Firefox*) break ;; esac
    read -ru $dummySleep -t .002 _
done
read -ru $dummySleep -t .1 _
xdotool key --delay 200 Ctrl+l Return
read -ru $dummySleep -t .2 _
xdotool key --delay 200 Alt+p p

This script could comming to become usefull... Just edit 1st part for your need.

Upvotes: 8

Nickolay
Nickolay

Reputation: 32063

Add-ons can't be "run" (what does it mean to run Adblock from command line, for example?).

If the add-ons you're using do not support command-line params. you can write an extension that checks the command line and calls an appropriate function of the whatever other add-on you want to "run".

Upvotes: 2

Related Questions