fix: remove force-unwrap crash risk, Safari UA, IPv4 URL handling, snapshot logical dims#2
fix: remove force-unwrap crash risk, Safari UA, IPv4 URL handling, snapshot logical dims#2shashank-sn wants to merge 2 commits into
Conversation
…x snapshot dims - Fix force-unwrap crash in mouse monitor: optional-chain window/contentView during HUD dismiss instead of force-unwrap - Set full Safari user agent via customUserAgent on WKWebView - smartURL now prefers http:// for bare IPv4 addresses with optional ports - Snapshot dimensions report logical points (Retina px / backingScaleFactor) Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
… scale factor Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
Greptile SummaryThis PR applies several small fixes in the single Swift app file.
Confidence Score: 4/5The user-agent change should be fixed before merging.
main.swift Important Files Changed
Reviews (1): Last reviewed commit: "fix: remove dead applicationNameForUserA..." | Re-trigger Greptile |
| @@ -237,6 +240,7 @@ final class BrowserWindowController: NSWindowController, NSWindowDelegate, | |||
| conf.userContentController.addUserScript(hideWebAuthn) | |||
There was a problem hiding this comment.
Hard-Coded Platform User Agent
Every web navigation now sends a fixed Intel Mac OS X 10_15_7 user agent instead of WebKit's current platform string. On newer macOS releases or Apple Silicon Macs, sites that choose downloads or compatibility code from the UA can serve the wrong content, while the previous configuration suffix preserved the real OS and platform tokens.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| @@ -506,13 +511,17 @@ final class BrowserWindowController: NSWindowController, NSWindowDelegate, | |||
|
|
|||
There was a problem hiding this comment.
When window?.screen and NSScreen.screens.first are unavailable during a snapshot, this falls back to 2.0 even though WebKit may render the off-screen snapshot at 1x. In that state the PNG is written at its real pixel size, but the CLI output and GUI toast can report half of the file's actual dimensions.
Four bug fixes to main.swift (+16/−7 lines):
Remove force-unwrap crash risk — the mouse monitor HUD-dismiss path used
self.window!.contentView!.convert(...). Between theguard let selfand this line,self.windowcould become nil during window teardown, producing aFatal error: Unexpectedly found nil. Replaced with optional chain:self.window?.contentViewbound aslet contentView.Set real Safari user agent — the old code used
applicationNameForUserAgentwhich only appends a suffix token to WKWebView's default UA, not actually present as Safari. Replaced withcustomUserAgentusing Safari 26.x's UA string on the WKWebView.Bare IPv4 addresses →
http://instead ofhttps://—smartURLused.contains(".")as a domain heuristic and prependedhttps://, but bare IPv4 addresses also contain dots (e.g.192.168.1.1:8080). Added an IPv4 regex check before thehttps://fallback so LAN IPs gethttp://.Snapshot dimensions report logical points, not Retina pixels —
takeSnapshotproduces Retina-scale images (2x/3x). Both CLI--snapand GUI⇧⌘Snow divide bybackingScaleFactor(from the window's screen) so a 1440×900 window reports(1440×900 px)not(2880×1800 px).All four orthogonal — each touches a distinct place in the file. Committed as two clean commits.
Validation
Built with
./build.shon macOS 26 (arm64, 2x Retina), then verified:--snap /tmp/test.png --size 800x600correctly reports(800x600 px)open Chromeless.app→ window renders, ⌘L HUD appearsPrior discussion
Plan:
docs/plans/2026-07-04-001-fix-chromeless-bugs-plan.mdReview: attached in session