Last active
November 17, 2025 13:15
-
-
Save mattppal/c7bd1a522e8ad0e20436412a7be8d293 to your computer and use it in GitHub Desktop.
Get Chrome viewport size and header height
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
| osascript \ | |
| -e 'tell application "Google Chrome"' \ | |
| -e 'set b to bounds of front window' \ | |
| -e 'set h to (item 4 of b) - (item 2 of b)' \ | |
| -e 'set v to execute active tab of front window javascript "JSON.stringify([window.innerWidth, window.innerHeight])"' \ | |
| -e 'set AppleScript'"'"'s text item delimiters to ","' \ | |
| -e 'set vList to text items of (text 2 thru -2 of v)' \ | |
| -e 'set vW to item 1 of vList as number' \ | |
| -e 'set vH to item 2 of vList as number' \ | |
| -e 'set chromeH to h - vH' \ | |
| -e 'set aspectRatio to (vW / vH)' \ | |
| -e 'return "Viewport: " & vW & "x" & vH & " | Chrome Header: " & chromeH & " | Aspect Ratio: " & aspectRatio' \ | |
| -e 'end tell' |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script returns the viewport size and header height of a Google Chrome window:
If your aspect ratio is not 16:9 (1.778), adjust the window height to match. This is useful for creating perfect 16:9 viewports for screen recordings.
Using with Raycast:
First, enable JavaScript from Apple Events: Go to Chrome > View > Developer > Allow JavaScript from Apple Events
Then,
Works with any window manager that lets you set exact dimensions (Raycast, Rectangle, Moom, etc.).