如何在Py或AHK等脚本中跳转到Edge浏览器内置页面(如edge://extensions/)

如题, 如何在Py或AHK等脚本中跳转到Edge浏览器内置页面(如edge://extensions/)?

你用win+r输入microsoft-edge:edge://extensions/看看能不能打开,能打开按这个思路让ai去处理

我本地并无edge无法帮你测试,这个是我23年左右收藏的方案,那时候是可以用的

好像不行,会打开一个空白页

不能打开内置,那就模拟操作咯
1.打开 edge
2.通过uia操作edge地址栏输入并回车

让 ai 写了几行powershell 测试(复制粘贴测试必须保留最后一行空白,不然没回车没办法模拟发送回车)

$ErrorActionPreference = 'Stop'
Add-Type -AssemblyName UIAutomationClient
Add-Type -AssemblyName UIAutomationTypes

$edgeExe = 'C:\Program Files (x86)\Microsoft\EdgeCore\155.0.4283.62\msedge.exe'
$url = 'edge://extensions/'

function Get-EdgeWindowProcess {
    Get-Process -Name msedge -ErrorAction SilentlyContinue |
        Where-Object { $_.MainWindowHandle -ne 0 } |
        Select-Object -First 1
}

$edgeProcess = Get-EdgeWindowProcess
$hadWindow = $null -ne $edgeProcess

if (-not $hadWindow) {
    Start-Process -FilePath $edgeExe | Out-Null
}

$watch = [System.Diagnostics.Stopwatch]::StartNew()
while (-not $edgeProcess -and $watch.Elapsed.TotalSeconds -lt 15) {
    $edgeProcess = Get-EdgeWindowProcess
    if (-not $edgeProcess) {
        [System.Threading.Thread]::Yield() | Out-Null
    }
}
if (-not $edgeProcess) {
    throw '超时:没有找到 Edge 窗口。'
}

$wshell = New-Object -ComObject WScript.Shell
if (-not $wshell.AppActivate([int]$edgeProcess.Id)) {
    throw '无法激活 Edge 窗口。'
}

if ($hadWindow) {
    $wshell.SendKeys('^t')
}
$wshell.SendKeys('^l')

$watch.Restart()
$valuePattern = $null

while (-not $valuePattern -and $watch.Elapsed.TotalSeconds -lt 5) {
    try {
        $focused = [System.Windows.Automation.AutomationElement]::FocusedElement
        if ($focused.Current.ControlType -eq
            [System.Windows.Automation.ControlType]::Edit) {
            $pattern = $null
            if ($focused.TryGetCurrentPattern(
                [System.Windows.Automation.ValuePattern]::Pattern,
                [ref]$pattern
            )) {
                $valuePattern = $pattern
            }
        }
    } catch {}

    if (-not $valuePattern) {
        [System.Threading.Thread]::Yield() | Out-Null
    }
}

if (-not $valuePattern) {
    throw '超时:UIA 没有取得支持 ValuePattern 的地址栏。'
}

$valuePattern.SetValue($url)
$wshell.SendKeys('{ENTER}')

出现空白页说明浏览器其实已经启动了,只是 edge:// 这类特权地址在传入的过程中被丢掉了。在地址栏里输入这个地址属于浏览器内部发起的导航,和把 URL 交给负责启动浏览器的那个进程走的是两条不同的路径。

如果不能一步到位,那考虑半自动?

先启动Edge浏览器
使用Eged的快捷键,将焦点聚焦到地址栏
粘贴内置页面的命令,回车