screenshot-browserless.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/bash
  2. set -euo pipefail
  3. # Klimbim Software collection, A bag full of things
  4. # Copyright (C) 2011-2024 Johannes 'Banana' Keßler
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. # 2024 http://www.bananas-playground.net
  19. # A simple wrapper around browserless requests based on the free acccount.
  20. # You need an API.
  21. # Important note: It will not always work. This is not an error. It depends
  22. # on the way the target webpage is build.
  23. command -v curl >/dev/null 2>&1 || { echo >&2 "I require curl (https://curl.haxx.se/) but it's not installed. Aborting."; exit 1; }
  24. # add your browserless io token
  25. BROWSERLESSURL="https://chrome.browserless.io/screenshot?token=XXXXXXXXX"
  26. USAGE="screenshot-browserless.sh 'URL' file.jpeg"
  27. if [ $# -lt 2 ]; then
  28. echo "Missing required URL or file";
  29. echo ${USAGE}
  30. exit 2;
  31. fi;
  32. curl -s -X POST "${BROWSERLESSURL}" -H 'Cache-Control: no-cache' -H 'Content-Type: application/json' \
  33. -d '{"url": "'"${1}"'", "waitFor" : 5000, "options": { "fullPage": true,"type": "jpeg","quality": 75 } }' -o ${2}