Issue with script to inject bookmarks into Edge (Chromium based) and Google Chrome

101 Views Asked by At

I've got a script that injects bookmarks into Edge or Chrome. For the most part, it works reasonably well, however, when the browser is relaunched, the name of the favorite is stripped out. The bookmark shows up with a blank document icon and no name. (After going to the site the favicon is added back to the bookmark, so I'm not concerned about that). So, my question is how can I get it to not do that?

When I look at the bookmarks file before launching the browser, the name is there, but after launching the browser, the name is gone. I followed this script: https://stackoverflow.com/questions/75642929/add-a-bookmark-to-microsoft-edge-bookmark-bar-with-powershell to create my script.
The relevant parts of my script go like this:

$bookmarkPath = "$env:localappdata\Microsoft\Edge\User Data\Default\bookmarks"
$Bookmarks = Get-Content -path $bookmarkpath

$NewBookmark = [pscustomobject][ordered]@{
    guid = (New-Guid).Guid
    name = 'Name from CSV'
    show_icon = $true
    source = 'user_copy'
    type = 'url'
    url = 'URL from CSV'
}
$Bookmarks.roots.bookmark_bar.children += $NewBookmark
$Bookmarks.psobject.properties.remove('checksum')
Try {
    $Bookmarks | ConvertTo-Json -Depth 10 | Set-content -Path $bookmarkPath -force
}
catch {
    $_.exception.message
}

As an example, this is what I see:

{
    "roots": {
        "bookmark_bar": {
            "children": [ {
                "date_added": "13353700456516",
                "date_last_used": "0",
                "guid": "eecb133a-98f9-497b-8ab3-692646b7df74",
                "id": "2",
                "name": "Google",
                "show_icon": true,
                "source": "user_copy",
                "type": "url",
                "url": "https://www.google.com"
            }
      ...
}

and after launching:

{
    "roots": {
        "bookmark_bar": {
            "children": [ {
                "date_added": "13353700456516",
                "date_last_used": "13353700708627",
                "guid": "eecb133a-98f9-497b-8ab3-692646b7df74",
                "id": "2",
                "name": "",
                "show_icon": true,
                "source": "user_copy",
                "type": "url",
                "url": "https://www.google.com"
            }
      ...
}

I'd expect the name to not be stripped out. I've tried changing the [pscustomobject] properties down to the minimum set of properties (name, url, type, url) and it still happens.
I get the same result no matter how many bookmarks I add this way.. they all have the name stripped out when the browser gets re-written.

1

There are 1 best solutions below

3
Kendrick Li On

I can't reproduce this issue with your code. Particularly, I can't even add bookmarks without ConvertFrom-Json.

Anyway, I suppose you should change "show_icon": true into false. "show_icon": true means show icon only, so there won't be a name displayed for that bookmark.