Mac hosting guide

Safari WebRTC Permission Prompts on macOS

Drive Safari with XCUITest, register an interruption monitor before navigating, wait on a DOM state instead of sleep, and attach the dialog screenshot to the .xcresult. A full camera and microphone stream test needs real hardware you control.

Figment editorial teamPublished Updated Facts checked November 10, 2026

Figment Mac plans

US East. Pay before use. Hourly and daily too.

Intel Mac VM4 shared vCPUs, 4GB RAM, 80GB SSD$25per monthApple Silicon Mac VM4 shared vCPUs, 4GB RAM, 65GB SSD$39per monthDedicated M4 Pro12-core CPU, 24GB RAM, 512GB SSD$199per month

Minimum first purchase: $25 of account credit, used for your rental.

To test Safari's camera and microphone dialog, run an XCUITest on a real macOS session with a working TCC daemon, register an interruption monitor before navigating, and wait on a DOM state rather than a fixed delay. A full getUserMedia({video:true, audio:true}) stream test also needs a camera and microphone. Cameras and microphones are not available or measured on any Figment plan, so that part needs a physical Mac you control.

Why does this test need a real macOS session?

macOS enforces camera and microphone access through Transparency, Consent, and Control (TCC). When Safari calls getUserMedia(), macOS checks whether the user has granted camera or microphone access to Safari and, if not, shows a system-level permission dialog owned by the TCC subsystem, not Safari.

The iOS Simulator does not surface a user-level TCC prompt for WebRTC, and WebView mocks that return a canned MediaStream cannot exercise the dialog at all. An XCUITest designed to tap an Allow button fails in the Simulator because there is no button to tap. A real macOS session, whether a developer workstation or a hosted Mac, is the only place the full code path runs.

Which entitlements and Info.plist keys does the test host need?

The test host needs the camera and microphone usage strings, and, under Hardened Runtime, the matching entitlements. Apple's media-capture authorization documentation lists them (Apple: Requesting authorization to capture and save media). Without the usage descriptions, macOS suppresses the dialog silently:

<!-- TestHostApp-Info.plist -->
<key>NSCameraUsageDescription</key>
<string>Automated test verifying WebRTC camera permission flow</string>
<key>NSMicrophoneUsageDescription</key>
<string>Automated test verifying WebRTC microphone permission flow</string>

For macOS apps built with Hardened Runtime, the entitlements file also needs:

<key>com.apple.security.device.camera</key>
<true/>
<key>com.apple.security.device.microphone</key>
<true/>

Without these, AVCaptureDevice.requestAccess(for:) returns .denied and the system records a silent rejection rather than prompting. These keys belong on your test host or wrapper app. Safari already ships with the required entitlements, and resetting its TCC entry is what makes the prompt reappear.

How do I trigger getUserMedia() and intercept the dialog?

Load a minimal HTML page in Safari that calls navigator.mediaDevices.getUserMedia({video: true, audio: true}) on page load, and register the interruption monitor before navigation. addUIInterruptionMonitor is defined on XCTestCase, and per Apple's XCUIApplication reference, XCUIApplication(bundleIdentifier:) launches Safari by its bundle identifier:

import XCTest

final class SafariWebRTCPermissionTests: XCTestCase {

    func testGrantCameraAndMicPermission() throws {
        let safari = XCUIApplication(bundleIdentifier: "com.apple.Safari")

        // Register BEFORE launching/navigating so the handler is armed.
        addUIInterruptionMonitor(withDescription: "Camera/Mic permission") { alert in
            let allow = alert.buttons["Allow"]
            guard allow.exists else { return false }
            allow.tap()
            return true
        }

        safari.launch()
        safari.typeKey("l", modifierFlags: .command)
        let addressBar = safari.windows.firstMatch.textFields.firstMatch
        XCTAssert(addressBar.waitForExistence(timeout: 3), "Address bar did not appear")
        addressBar.typeText("http://localhost:8080/webrtc-test.html\n")

        // XCTest processes pending interruptions on the next interaction.
        safari.tap()
    }
}

addUIInterruptionMonitor only fires while there is a subsequent interaction with the host app, which is why safari.tap() follows the navigation. Without that nudge the handler can sit dormant and the test times out holding a visible dialog.

How do I assert permission state without sleep()?

Replace fixed delays with XCTNSPredicateExpectation. Have the test page flip a visible DOM element from "Requesting…" to "Stream active: video+audio" once the getUserMedia() promise resolves, then wait on that condition:

func assertWebRTCGranted(in safari: XCUIApplication, timeout: TimeInterval = 10) {
    let status = safari.webViews.firstMatch
        .staticTexts.matching(
            NSPredicate(format: "label BEGINSWITH 'Stream active'")
        ).firstMatch

    let expectation = XCTNSPredicateExpectation(
        predicate: NSPredicate(format: "exists == true"),
        object: status
    )
    let result = XCTWaiter().wait(for: [expectation], timeout: timeout)
    XCTAssertEqual(result, .completed,
        "Stream active never appeared; permission may have been denied or getUserMedia rejected")
}

This gives XCTest a concrete, timing-independent condition and stops a flaky sleep(3) from masking a real failure. If the promise rejects, the DOM text never changes and the expectation fails with a useful message instead of a green build on a broken stream.

How do I capture screenshot evidence of the dialog?

Grab the screenshot inside the interruption monitor so the dialog is still visible, and set lifetime = .keepAlways so the attachment is kept on passing runs too:

addUIInterruptionMonitor(withDescription: "Camera/Mic permission") { alert in
    let shot = alert.screenshot()
    let attachment = XCTAttachment(screenshot: shot)
    attachment.name = "webrtc-permission-dialog"
    attachment.lifetime = .keepAlways
    self.add(attachment)

    alert.buttons["Allow"].tap()
    return true
}

The attachment lands in the .xcresult bundle for the run. Browse it from the Xcode Report Navigator or extract it with xcrun xcresulttool get --path Build.xcresult --format json. Name attachments deterministically, not with a timestamp, if you want stable diffs across runs.

How do I reset TCC state between CI jobs?

Run tccutil reset for each service before every job. It clears stored decisions for a service and bundle identifier, so the next access shows a fresh dialog:

#!/bin/bash
set -euo pipefail
tccutil reset Camera     com.apple.Safari
tccutil reset Microphone com.apple.Safari

Run this as a pre-test step on the Mac agent. Without sudo it only affects the user-level TCC database, which is what Safari uses in a user-session CI agent. If you run several test classes per job, put the reset in setUp() on a shared base XCTestCase so it executes before every test method.

Which part of the WebRTC prompt test can a Mac VM cover?

Use either VM for the dialog plumbing: the XCUITest setup, the Info.plist and entitlement work, and the tccutil reset. You have administrator access to your own Mac or VM, which the TCC reset needs. The Intel Mac VM ($25 a month, $2 a day) runs macOS Sequoia with Xcode 26.3 or earlier. The Apple Silicon Mac VM ($39 a month, $6 a day) fits if you need Xcode 26.4 or later.

We have not measured whether Safari shows the camera dialog on a Figment VM that has no camera, and the end-to-end stream assertion needs a real camera and microphone. Run that part on a physical Mac you control. See the Mac hosting plans.

For market context, CloudMac lists a dedicated Mac mini M4 (16 GB / 256 GB) at $99.99/month and a $999/year option on its homepage and pricing page, roughly $83.25/month effective. The Dedicated M4 Pro 48 GB ($349 a month, whole Mac, 48GB) is the whole-Mac comparison, and twelve months of the Apple Silicon Mac VM is 12 × $39 = $468.

Related guides:

Which Figment Mac fits this work?

Intel Mac VM from $25 a month, Apple Silicon Mac VM from $39, or a Dedicated M4 Pro for $199. Hourly and daily plans too. You pay before use, starting with at least $25 of account credit.

Choose a Mac plan