webdriver_manager icon indicating copy to clipboard operation
webdriver_manager copied to clipboard

An error occurred while initializing Chrome with profile and logging: Message: unknown error: cannot parse internal JSON template: Line: 1, column: 1, Unexpected token.

Open gauthierbuttez opened this issue 1 year ago • 3 comments

I think there is an incompatibility issue:

Environment: Windows 10 Selenium 4.10 Python 3.10.7 webdriver-manager 4.0.1 Chrome Version 122.0.6261.112 (Build officiel) (64 bits)

I want to open Chrome browser with my profile. I tried everything ChatGPT suggested to me. I alway get the same issue:

An error occurred while initializing Chrome with profile and logging: Message: unknown error: cannot parse internal JSON template: Line: 1, column: 1, Unexpected token.

So I asked chatGPT to ignore my code and to make a new script from scratch. The prompt:

ok. Well nothing work. So let's do it another way. Ignore my code and make yourself from scratch a function that open chrome driver with selenium 4.18.1.

After correcting some minor issues, He gave me this code:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
import os

def initialize_chrome_with_profile_and_logging():
    try:
        # Specify the path to the user's Chrome profile
        profile_path = os.path.join(os.environ['LOCALAPPDATA'], 'Google', 'Chrome', 'User Data')
        options = webdriver.ChromeOptions()
        options.add_argument(f'user-data-dir={profile_path}')  # Path to your chrome profile

        # Enable verbose logging and specify log file path
        service = ChromeService(ChromeDriverManager().install())
        log_path = os.path.join(os.getcwd(), 'chromedriver.log')
        service.start(args=['--verbose', '--log-path=' + log_path])
        
        # Initialize the Chrome driver with options and service
        driver = webdriver.Chrome(service=service, options=options)
        return driver
    except Exception as e:
        print(f"An error occurred while initializing Chrome with profile and logging: {e}")
        return None

Can anyone have time to reproduce this issue?

I don't know if it is my PC or is there a bug?

gauthierbuttez avatar Mar 07 '24 11:03 gauthierbuttez

did you find a solution yet?

nkinapsg avatar Mar 12 '24 19:03 nkinapsg

gauthierbuttez

I don’t think this has anything to do with compatibility and your task of using a user profile. Cuz the error is related to parse JSON.

Delete what is located along the path(json and a directory with drivers): \Users\%userprofile%\.wdm It worked for me.

Maybe you, like me, did not close the running driver and used caching with webdriver_manage.

If you need to open a user profile, you need to look in "Commands Chronium". I solve the problem myself, it is not that simple, especially in headless mode

KashitsynArtem avatar Mar 22 '24 10:03 KashitsynArtem

did you find a solution yet?

Harmoury avatar May 31 '24 14:05 Harmoury