# Buggy code
def get_chrome_bookmark_urls(path):
    """Return a list of bookmarked URLs in Google Chrome/Chromium"""
    import json

    # read file to parser
    with open(path, "r") as f:
        js = json.load(f)

    # empty list
    urls = []

    # local recursive function
    def get_chrome_bookmark_urls_helper(node):
        if not isinstance(node, dict):
            return
        if "type" not in node:
            return
        if node["type"] == "folder":
            # folders have children
            for child in node["children"]:
                get_chrome_bookmark_urls_helper(child)
        if node["type"] == "url" and "url" in node:
            urls.append(node["url"])

    # find bookmarks
    for node in js["roots"]:
        get_chrome_bookmark_urls_helper(js["roots"][node])

    return list(set(urls))  # unique


# Traceback (UnicodeDecodeError)
Błąd: google_chrome.cache: Command to clean JSON file, path=C:\Users\UserXXX\AppData\Local\Google\Chrome\User Data\Default\Preferences, address=dns_prefetching/host_referral_list
Traceback (most recent call last):
File "C:\projects\bleachbit\bleachbit\Worker.py", line 87, in execute
File "C:\projects\bleachbit\bleachbit\Command.py", line 244, in execute
File "C:\projects\bleachbit\bleachbit\FileUtilities.py", line 263, in clean_json
File "C:\Python34\lib\json\__init__.py", line 265, in load
File "C:\Python34\lib\encodings\cp1250.py", line 23, in decode
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 28203: character maps to <undefined>
Błąd: google_chrome.cache: Command to clean JSON file, path=C:\Users\UserXXX\AppData\Local\Google\Chrome\User Data\Default\Preferences, address=dns_prefetching/startup_list
Traceback (most recent call last):
File "C:\projects\bleachbit\bleachbit\Worker.py", line 87, in execute
File "C:\projects\bleachbit\bleachbit\Command.py", line 244, in execute
File "C:\projects\bleachbit\bleachbit\FileUtilities.py", line 263, in clean_json
File "C:\Python34\lib\json\__init__.py", line 265, in load
File "C:\Python34\lib\encodings\cp1250.py", line 23, in decode
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 28203: character maps to <undefined>
Błąd: google_chrome.cache: Command to clean JSON file, path=C:\Users\UserXXX\AppData\Local\Google\Chrome\User Data\Default\Preferences, address=net/http_server_properties/servers
Traceback (most recent call last):
File "C:\projects\bleachbit\bleachbit\Worker.py", line 87, in execute
File "C:\projects\bleachbit\bleachbit\Command.py", line 244, in execute
File "C:\projects\bleachbit\bleachbit\FileUtilities.py", line 263, in clean_json
File "C:\Python34\lib\json\__init__.py", line 265, in load
File "C:\Python34\lib\encodings\cp1250.py", line 23, in decode
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 28203: character maps to <undefined>

# Fixed code
def get_chrome_bookmark_urls(path):
    """Return a list of bookmarked URLs in Google Chrome/Chromium"""
    import json

    # read file to parser
    with open(path, "r", encoding="utf-8") as f:
        js = json.load(f)

    # empty list
    urls = []

    # local recursive function
    def get_chrome_bookmark_urls_helper(node):
        if not isinstance(node, dict):
            return
        if "type" not in node:
            return
        if node["type"] == "folder":
            # folders have children
            for child in node["children"]:
                get_chrome_bookmark_urls_helper(child)
        if node["type"] == "url" and "url" in node:
            urls.append(node["url"])

    # find bookmarks
    for node in js["roots"]:
        get_chrome_bookmark_urls_helper(js["roots"][node])

    return list(set(urls))  # unique