Created
February 24, 2020 17:05
-
-
Save sloev/cc00948856334d3530b5f283633724c0 to your computer and use it in GitHub Desktop.
osx python 3 headless chrome screenshot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import subprocess | |
| import json | |
| URL = "https://www.google.com" | |
| get_browser_bundle_id = "cat ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist | plutil -convert json -r -o - -- -" | |
| json_string = subprocess.check_output(get_browser_bundle_id, shell=True) | |
| json_data = json.loads(json_string) | |
| browser_bundle_id = [e for e in json_data['LSHandlers'] if e.get("LSHandlerURLScheme") == "http"][0]['LSHandlerRoleAll'] | |
| browser_app_path = f"/usr/bin/defaults read {browser_bundle_id} LastRunAppBundlePath" | |
| browser_path = subprocess.check_output(browser_app_path, shell=True).strip().decode("utf-8") | |
| browser_path = f"{browser_path}/Contents/MacOS/{browser_path.rsplit('.app', 1)[0].rsplit('/', 1)[1]}".replace(" ", "\ ") | |
| screen_shot_command = f"{browser_path} --headless --disable-gpu --screenshot=lol.png {URL}" | |
| output = subprocess.check_output(screen_shot_command, shell=True) | |
| print(output) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment