I am using either a chromium or firefox web browser in kiosk mode to log in to a website from boot up, and I want to use a javascript to send in a command to login to a website automatically. I know how to write the javascript, but I do not know how to "pipe" the javascript into the web browser from a terminal bash file. Also, I am working in Linux.
2 Answers
In OS X you can use AppleScript to run JavaScript in Chrome:
xj(){ osascript -e'on run{a}' -e'tell app"google chrome"to tell active tab of window 1 to execute javascript a' -eend "$1"; }
Firefox does not support AppleScript.
I am not sure Firefox is capable of doing what you want here even though there are lots of command line options for launching Firefox from a script.
Chrome has even more options and may be able to pull off executing javascript from a local source, but I doubt it.
If you could somehow pass javascript in through the developer console then you could definitely execute arbitrary code in a web browser session (i.e. an automated login or what not).
A Hack
Since you can definitely specify a starting url from a script for both browsers, perhaps the following will work 1:
Write a script that automatically navigates to the web page that you want to login to and completes the login process, (i.e.
POSTthe login form, whatever).Save this file to your disk and make sure that the user can read it.
Launch Firefox and point it to this file:
./firefox -url "file:///home/thisUser/desktop/foo.html"
I am not sure that the url scheme file:/// will work in all situations but I did test it on OSX.
This should load the file and try to render the content. The file:/// thing is just a way not to have to run a web server on localhost, but that could work too.
You might run into XSS problems or other obstacles to doing a remote login so you may have to revert to a server side script and just point the browser at a localhost web server.
Best of luck!
1 I haven't tested this all the way just tossing out an idea.