Skip to content

fix: remove force-unwrap crash risk, Safari UA, IPv4 URL handling, snapshot logical dims#2

Open
shashank-sn wants to merge 2 commits into
antiwork:mainfrom
shashank-sn:fix/four-bugs
Open

fix: remove force-unwrap crash risk, Safari UA, IPv4 URL handling, snapshot logical dims#2
shashank-sn wants to merge 2 commits into
antiwork:mainfrom
shashank-sn:fix/four-bugs

Conversation

@shashank-sn

Copy link
Copy Markdown

Four bug fixes to main.swift (+16/−7 lines):

  1. Remove force-unwrap crash risk — the mouse monitor HUD-dismiss path used self.window!.contentView!.convert(...). Between the guard let self and this line, self.window could become nil during window teardown, producing a Fatal error: Unexpectedly found nil. Replaced with optional chain: self.window?.contentView bound as let contentView.

  2. Set real Safari user agent — the old code used applicationNameForUserAgent which only appends a suffix token to WKWebView's default UA, not actually present as Safari. Replaced with customUserAgent using Safari 26.x's UA string on the WKWebView.

  3. Bare IPv4 addresses → http:// instead of https://smartURL used .contains(".") as a domain heuristic and prepended https://, but bare IPv4 addresses also contain dots (e.g. 192.168.1.1:8080). Added an IPv4 regex check before the https:// fallback so LAN IPs get http://.

  4. Snapshot dimensions report logical points, not Retina pixelstakeSnapshot produces Retina-scale images (2x/3x). Both CLI --snap and GUI ⇧⌘S now divide by backingScaleFactor (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.sh on macOS 26 (arm64, 2x Retina), then verified:

  • --snap /tmp/test.png --size 800x600 correctly reports (800x600 px)
  • open Chromeless.app → window renders, ⌘L HUD appears
  • ⌘L click-outside dismisses without crash

Prior discussion

Plan: docs/plans/2026-07-04-001-fix-chromeless-bugs-plan.md
Review: attached in session

shashank-sn and others added 2 commits July 4, 2026 10:23
…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-apps

greptile-apps Bot commented Jul 4, 2026

Copy link
Copy Markdown

Greptile Summary

This PR applies several small fixes in the single Swift app file.

  • Safer HUD click-outside handling during window teardown.
  • A full custom Safari-style WKWebView user agent.
  • HTTP handling for bare IPv4 address inputs.
  • Snapshot dimension reporting adjusted for backing scale.

Confidence Score: 4/5

The user-agent change should be fixed before merging.

  • Web requests now advertise a fixed Intel macOS 10.15 platform string on every machine.
  • Snapshot reporting has a narrower fallback-scale case that can print incorrect dimensions.
  • The nil-safe HUD path and IPv4 routing change look contained.

main.swift

Important Files Changed

Filename Overview
main.swift Updates URL parsing, WKWebView UA setup, HUD dismissal, and snapshot dimension reporting; the UA override now hard-codes stale platform tokens.

Reviews (1): Last reviewed commit: "fix: remove dead applicationNameForUserA..." | Re-trigger Greptile

Comment thread main.swift
@@ -237,6 +240,7 @@ final class BrowserWindowController: NSWindowController, NSWindowDelegate,
conf.userContentController.addUserScript(hideWebAuthn)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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!

Comment thread main.swift
@@ -506,13 +511,17 @@ final class BrowserWindowController: NSWindowController, NSWindowDelegate,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Fallback Scale Halves Reports

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant