# PowerShell script to setup Chrome permissions for microphone access # This script creates a Chrome preferences file that auto-grants microphone permissions param( [string]$ChromeUserData = "$env:TEMP\chrome-digital-human", [string]$Origin = "http://localhost:3000" ) # Create Chrome user data directory if it doesn't exist if (-not (Test-Path $ChromeUserData)) { New-Item -ItemType Directory -Path $ChromeUserData -Force | Out-Null } # Create Default directory for preferences $DefaultDir = Join-Path $ChromeUserData "Default" if (-not (Test-Path $DefaultDir)) { New-Item -ItemType Directory -Path $DefaultDir -Force | Out-Null } # Create Preferences file path $PreferencesPath = Join-Path $DefaultDir "Preferences" # Read existing preferences $existingJson = "{}" if (Test-Path $PreferencesPath) { try { $existingJson = Get-Content $PreferencesPath -Raw -ErrorAction SilentlyContinue if ([string]::IsNullOrWhiteSpace($existingJson)) { $existingJson = "{}" } } catch { $existingJson = "{}" } } # Parse existing JSON try { $prefs = $existingJson | ConvertFrom-Json } catch { $prefs = @{} | ConvertTo-Json | ConvertFrom-Json } # Function to ensure nested object exists function Ensure-Object { param($obj, $path) $parts = $path -split '\.' $current = $obj foreach ($part in $parts) { if (-not $current.$part) { $current | Add-Member -MemberType NoteProperty -Name $part -Value (@{} | ConvertTo-Json | ConvertFrom-Json) -Force } $current = $current.$part } return $current } # Ensure all required objects exist Ensure-Object $prefs "profile" | Out-Null Ensure-Object $prefs "profile.content_settings" | Out-Null Ensure-Object $prefs "profile.content_settings.exceptions" | Out-Null Ensure-Object $prefs "profile.content_settings.exceptions.media_stream_mic" | Out-Null Ensure-Object $prefs "profile.content_settings.exceptions.media_stream_camera" | Out-Null # Set microphone permission (1 = Allow) $micKey = "$Origin,*" $micPerm = @{ setting = 1 } | ConvertTo-Json | ConvertFrom-Json $prefs.profile.content_settings.exceptions.media_stream_mic | Add-Member -MemberType NoteProperty -Name $micKey -Value $micPerm -Force # Set camera permission (1 = Allow) $cameraKey = "$Origin,*" $cameraPerm = @{ setting = 1 } | ConvertTo-Json | ConvertFrom-Json $prefs.profile.content_settings.exceptions.media_stream_camera | Add-Member -MemberType NoteProperty -Name $cameraKey -Value $cameraPerm -Force # Save preferences try { $json = $prefs | ConvertTo-Json -Depth 20 Set-Content -Path $PreferencesPath -Value $json -Encoding UTF8 -Force exit 0 } catch { exit 1 }