Skip to content

feat(mobile): keep the Glasshouse page out of screenshots and recordings on iPhone - #202

Merged
geoolekom merged 4 commits into
mainfrom
mobile-ios-hide-from-screenshots
Nov 26, 2026
Merged

geoolekom merged 4 commits into
mainfrom
mobile-ios-hide-from-screenshots

Conversation

@geoolekom

@geoolekom geoolekom commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Keeps the Glasshouse page out of screenshots and screen recordings on iPhone by moving a layer into the canvas layer of a secure UITextField (isSecureTextEntry = true). The method follows Expo's packages/expo-screen-capture/ios/SecureWindowCanvas.swift and ScreenCaptureModule.swift; the code here is written again for this app.

The cost: the whole window is hidden, not only the page

The layer that moves is the layer of the page's window. While the Glasshouse page is on the screen, a screenshot or a recording of a real iPhone is expected to show nothing of the window: the address bar and the tab bar too, not only the page. No "Restricted page" sign can be shown in the picture, because it would be in the window as well, so that sign is not in this PR.

I first moved the layer of the page's own container (commit 1 of this branch), because it hides only the page. It does not work:

  • A web view takes no keyboard focus while the layer of one of its views, or of a view above it, is out of its superview's layer. UIKit refuses becomeFirstResponder(), so nothing can be typed into a field of the page. Moving the layer of the view SwiftUI puts around the page failed the same way.
  • With the layer of a view in the canvas, UIKit no longer knows that view's real parent. Removing the parent while the layer is there, or freeing the window, crashes UIKit (SIGSEGV in _didMoveFromWindow:toWindow:). This happened in a unit test and in the app.

The window has no superview, so moving its layer has neither problem; this is also what Expo does. If hiding only the page matters more than typing, this needs another idea. I did not find one.

What changed

  • GlasshouseScreenshotShield makes the secure field (no touches, clear background, sized like the parent), puts its layer where the moved layer was, takes the field's first sublayer as the canvas, and moves the layer into it. If the system gives the field no canvas layer, nothing is changed and it says so.
  • Putting the layer back is safe to call twice, restores the layer that was moved (not the current one), and a failed try leaves nothing latched. A layer that something else already took out of the canvas is left where it is, and only the field goes. The moved layer tree is asked to redraw right after the move, one run-loop turn later, and 0.1 s later, because a move can drop drawing that was waiting.
  • GlasshouseWebHost (the view SwiftUI shows) keeps the web view filling it. When it gets a window in restricted mode, the window's layer is moved; when it leaves the window or the mode ends, the layer is put back. The view hierarchy does not change, so touches, scrolling, layout and text selection stay the web view's own.
  • The constant GlasshouseScreenshot.canBeBlocked is gone. GlasshouseRestriction takes the result of each try: when it worked there is no notice and the sign under the address bar says "Restricted mode: hidden from screenshots and recordings"; the "a screenshot cannot be blocked" notice shows only after a try that failed. The page stays hidden while the screen is being recorded.
  • The test page server has a long page (/long) for the scroll and tap test. The build number is 261126.2 (main already carried 261126.1). The README says how the method works, what it costs and what the Simulator cannot test.

What the Simulator could not show

The Simulator does not apply the screenshot protection to what it draws, so the black area (and the missing page in a recording) cannot be shown there, and no Simulator workaround is added. In the Simulator the secure field does give a canvas layer (a unit test checks this with the real field), and the app, with the real window's layer in the canvas, loads the page, scrolls, takes taps, selects text, types and keeps working when the person leaves the page and comes back (UI tests). The sign under the address bar says "hidden" only after the real try worked, so the UI test of that sign shows that the real window's layer was moved. Not covered: clipboard-manager tricks, dragging text out, the App Switcher snapshot, video DRM. The app has no pull-to-refresh, and rotation is covered at the layer level by the resize test.

What each new test shows

GlasshouseScreenshotShieldTests (unit, plain layers and the real secure field):

  • the layer moves into the canvas; protecting twice changes nothing more; restoring puts it back at its place; restoring twice changes nothing;
  • no canvas layer: the answer is false, the tree is unchanged and a second try can still work; no parent layer: false;
  • the layer that was moved is the one put back; a layer taken out of the canvas by something else is left alone; the field follows the parent's size; the redraws happen (three after a move, after a restore, none after a failed try);
  • a real secure UITextField gives a canvas layer in the Simulator.

GlasshouseWebHostTests (unit, a layer of their own stands in for the window's):

  • the layer moves when the host is on a window and is put back when it leaves; switching restricted mode off and on does the same; the host hands its own window to the code that picks the layer;
  • the web view fills the host and keeps its geometry on a resize (390x600 to 844x300); the field follows the parent's size when the host is laid out;
  • with a fake field that has no canvas layer the host tells "not protected" and the tree is unchanged; the state holder follows what the host tells.

GlasshouseRestrictionTests (unit, four new): nothing is said before a try; the notice shows after a failed try and goes when read; protected after a try that worked; the notice follows the last try and does not come back after it was read.

GlasshouseRestrictedTests (UI, in the real app): the sign says the page is hidden from screenshots and recordings, with no line asking to read anything; the page scrolls and takes a tap at the end of /long; the page keeps working, and a field of it takes typing, after the person leaves it and comes back.

What ran

  • Unit tests in the Simulator (iPhone 17, iOS 27.2): 111 run, 2 skipped, 0 failures, no crash.
  • UI tests in the Simulator (same device): 33 run, 33 passed, 0 failed (scripts/test-glasshouse-ios.py, about 11 minutes).
  • iosApp/check.sh (structure check and swiftlint lint --strict): clean, 0 violations. pre-commit run --all-files: passed.

To check on a real iPhone (from TestFlight after merge)

Open a page in Glasshouse and take a screenshot: it should be black or empty, with nothing of the app in it. Record the screen: the recording should show nothing of the app while the page is on the screen. Go to another tab: screenshots work there as before. Note the iOS version.

…ngs on iPhone

The Glasshouse page's container layer is moved into the canvas layer of a
secure text field, which the system leaves out of screenshots and screen
recordings. The view hierarchy stays as it is; only the layer tree changes.
The layer is put back when the page leaves the screen or restricted mode ends.

The restricted-mode sign sits behind the page and says the page is hidden from
screenshots and recordings. The notice that a screenshot cannot be blocked
shows only when the system gave the field no canvas layer, and then nothing is
changed.

Raises the build number to 261126.1.

Signed-off-by: Yehor Komarov <10210242+geoolekom@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a4bf9b18-1f71-4881-8433-252ef994106a
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

geoolekom and others added 3 commits November 26, 2026 17:36
…sh while it is hidden from screenshots

Moving the layer of a view of the page into the secure canvas stopped the web
view from taking keyboard focus, and removing the parent of such a view while
its layer was in the canvas crashed UIKit. The window has no superview, so the
layer of the window is moved instead, as Expo does: typing, scrolling, taps and
leaving and coming back to the page all work.

The cost is that everything the window shows is out of screenshots and
recordings while the page is on the screen, not the page alone. For that reason
the "Restricted page" sign behind the page is removed: no picture can show it.

The tests of the host are rewritten for the window and split into their own
file, with the shared test doubles in another; the README says what was tried
and what it costs.

Signed-off-by: Yehor Komarov <10210242+geoolekom@users.noreply.github.com>
`main` already carries build number 261126.1, which came in with another change, so this change
bumps the build number to the next one of the day.

Signed-off-by: Yehor Komarov <geoolekom@gmail.com>
Signed-off-by: Yehor Komarov <geoolekom@gmail.com>
@geoolekom
geoolekom merged commit 9d6da97 into main Nov 26, 2026
17 checks passed
@geoolekom
geoolekom deleted the mobile-ios-hide-from-screenshots branch November 26, 2026 14:45
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