简体   繁体   中英

Taking Screenshot of firefox webpage using shell scripting

I have some functions running in Unix terminals. In that functions -I want to incorporate this utility. I want to take a screenshot of the Firefox webpage using shell scripting.for example - in that function some HTML file is getting generated. I have to open that HTML file in Firefox using shell Cmd and then I have to make it full screen and take a screenshot of that Firefox window but the catch here is -I have multiple windows running the same function.so if I use that function in the different terminal at the same time - multiple Firefox will open and it is not taking a proper screenshot. Also, I want to mention here - I have tried xdotool in Unix but U am getting below error messages sometimes.

The script I am using

set window_id [ xdotool search --pid $pid --name "firefox" | tail -1]
xdotool search --onlyvisible --class "firefox" set_window $window_id windowraise
xdotool search --onlyvisible --class "firefox" set_window $window_id key F11
sleep 3
xdotool search --onlyvisible --class "firefox" set_window $window_id windowraise
sleep 2
import -window $window_id ~/image.jpg
xdotool windowactivate --sync $window_id
xdotool search --onlyvisible --class "firefox" set_window $window_id windowraise
xdotool search --onlyvisible --class "firefox" set_window $window_id key ctrl+q
sleep 0.1

to open a firefox using shell - I am using the below line

/usr/pkgs/firefox/bin/firefox --setDefaultBrowser --new-instance ~/test.html

also, I want to mention here - I have tried xdotool in UNIX but I am getting below error messages sometimes -

X Error of failed request: BadWindow (invalid Window parameter)

This is a working solution.

sudo apt-get install xautomation

sudo apt-get install gnome-screenshot

xte 'keydown Alt_L' 'key Tab' 'keyup Alt_L' 'key Tab`(send as many tabs as windows switchs)
gnome-screenshot

You can save this as a .sh file and run it as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM