You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用PowerShell合并Chrome与Edge Chromium的书签JSON文件

Edge Chromium迁移书签合并解决方案

问题根因

合并后children字段为空90%以上的概率是JSON序列化/反序列化时层级深度限制导致的:PowerShell默认的ConvertFrom-Json/ConvertTo-Json命令最大处理深度为2,书签结构超过该层级的内容会被直接截断,导致children字段丢失。

正确合并逻辑

Chrome与Edge的书签JSON结构完全兼容,核心合并规则如下:

  • 两份书签的根节点都存在roots字段,下含三个固定子节点:bookmark_bar(书签栏)、other(其他书签)、synced(移动设备同步书签)
  • 合并时以Edge书签为基准,将Chrome三个节点下的children数组内容去重后追加到Edge对应节点的children数组中即可

可用PowerShell实现代码

function Combine-Bookmarks {
    param(
        [Parameter(Mandatory=$true)]
        [string]$ChromeBookmarkPath,
        [Parameter(Mandatory=$true)]
        [string]$EdgeBookmarkPath,
        [Parameter(Mandatory=$true)]
        [string]$OutputPath
    )

    # 读取两份书签文件,指定深度避免层级截断
    $chromeBookmarks = Get-Content $ChromeBookmarkPath -Raw -Encoding UTF8 | ConvertFrom-Json -Depth 100
    $edgeBookmarks = Get-Content $EdgeBookmarkPath -Raw -Encoding UTF8 | ConvertFrom-Json -Depth 100

    # 定义需要合并的三个顶层书签节点
    $rootNodes = @("bookmark_bar", "other", "synced")

    foreach ($node in $rootNodes) {
        # 跳过Chrome中不存在的节点
        if (-not $chromeBookmarks.roots.PSObject.Properties[$node]) {
            continue
        }
        # 初始化Edge对应节点的children数组(如果为空)
        if (-not $edgeBookmarks.roots.$node.children) {
            $edgeBookmarks.roots.$node | Add-Member -MemberType NoteProperty -Name "children" -Value @() -Force
        }
        # 遍历Chrome的子条目,去重后追加
        $chromeChildren = $chromeBookmarks.roots.$node.children
        $existingEdgeEntries = $edgeBookmarks.roots.$node.children | ForEach-Object { $_.name + $_.url + $_.type }
        foreach ($child in $chromeChildren) {
            $entryKey = $child.name + $child.url + $child.type
            if ($entryKey -notin $existingEdgeEntries) {
                $edgeBookmarks.roots.$node.children += $child
            }
        }
    }

    # 导出合并后的书签,指定深度与编码
    $edgeBookmarks | ConvertTo-Json -Depth 100 | Out-File $OutputPath -Encoding UTF8NoBOM -Force
}

生效操作步骤

  1. 合并前执行taskkill /im msedge.exe /f关闭所有Edge进程,避免文件占用
  2. 将合并后的Bookmarks文件放入路径C:\Users\$UserID\AppData\Local\Microsoft\Edge\User Data\Default覆盖原文件
  3. 启动Edge即可直接读取合并后的完整书签

低版本PowerShell兼容处理

如果是PowerShell 5.1环境不支持UTF8NoBOM编码,导出后执行以下命令移除BOM即可:

$content = Get-Content $OutputPath -Raw -Encoding UTF8
[System.IO.File]::WriteAllText($OutputPath, $content, [System.Text.Encoding]::UTF8)

内容的提问来源于stack exchange,提问作者Gordon H

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 13:36:02