← Files Lexmount Browser AutomationARCHIVED FILE
skills/lexmount-cloud-browser/scripts/browser.ps1
2.59 KB · Nov 11, 2026 · 12:47 UTC
$ErrorActionPreference = "Stop"
$cliArgs = @($args)
$site = 'global'
$api = 'https://api.lexmount.com'
$connect = 'https://browser.lexmount.com'
$skillDir = Split-Path -Parent $PSScriptRoot
$installDir = if ($env:LEXMOUNT_BROWSER_CLI_INSTALL_DIR) { $env:LEXMOUNT_BROWSER_CLI_INSTALL_DIR } else { Join-Path $skillDir 'bin' }
$binary = Join-Path $installDir 'browser-cli.exe'
if (-not (Test-Path -LiteralPath $binary)) { throw "CLI is not installed. Run this Skill's scripts/bootstrap.ps1." }
foreach ($argument in $cliArgs) {
if ($argument -match '^--(connect-base-url|credentials-file)(=|$)') {
throw "This edition fixes its authorization site. Use LEXMOUNT_BROWSER_CREDENTIALS_FILE only for same-site task credentials."
}
}
if ($env:LEXMOUNT_BASE_URL -and $env:LEXMOUNT_BASE_URL.TrimEnd('/') -cne $api) {
throw "LEXMOUNT_BASE_URL conflicts with the installed $site edition."
}
if ($env:LEXMOUNT_API_KEY -or $env:LEXMOUNT_PROJECT_ID) {
if (-not $env:LEXMOUNT_API_KEY -or -not $env:LEXMOUNT_PROJECT_ID -or -not $env:LEXMOUNT_BASE_URL) {
throw "Managed credentials require both key and project plus this edition's explicit LEXMOUNT_BASE_URL."
}
}
$priorApi = $env:LEXMOUNT_BASE_URL
$priorCredentials = $env:LEXMOUNT_BROWSER_CREDENTIALS_FILE
$exitCode = 1
try {
$env:LEXMOUNT_BASE_URL = $api
if (-not $env:LEXMOUNT_BROWSER_CREDENTIALS_FILE) {
$userHome = [Environment]::GetFolderPath('UserProfile')
$env:LEXMOUNT_BROWSER_CREDENTIALS_FILE = Join-Path $userHome ".config/lexmount/browser-cli/sites/$site/credentials.json"
}
$authLogin = $cliArgs.Count -ge 2 -and $cliArgs[0] -eq 'auth' -and $cliArgs[1] -eq 'login'
$authLogout = $cliArgs.Count -ge 2 -and $cliArgs[0] -eq 'auth' -and $cliArgs[1] -eq 'logout'
$localOnly = $cliArgs.Count -gt 0 -and $cliArgs[0] -in @('version', '--help', '--version')
if ($authLogin) {
$cliArgs += @('--connect-base-url', $connect)
} elseif (-not $authLogout -and -not $localOnly -and -not $env:LEXMOUNT_API_KEY) {
$statusJson = & $binary auth status
if ($LASTEXITCODE -ne 0) { throw 'Cannot read credential status; repair same-site authorization before continuing.' }
$status = ($statusJson -join "`n") | ConvertFrom-Json
if (-not $status.ok) { throw 'Cannot read credential status.' }
$storedApi = $status.data.api_base_url
if ($storedApi -and $storedApi.TrimEnd('/') -cne $api) {
throw 'Credentials belong to another site; authorize this edition separately.'
}
}
& $binary @cliArgs
$exitCode = $LASTEXITCODE
} finally {
$env:LEXMOUNT_BASE_URL = $priorApi
$env:LEXMOUNT_BROWSER_CREDENTIALS_FILE = $priorCredentials
}
exit $exitCode
SHA-256: ce2d431d44d52c4a70f5313f7adc6ded7fe2958de2887772f0d77070f33a26d9