Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gauthierbuttez opened this issue Mar 7, 2024 · 3 comments

Comments

@gauthierbuttez
Copy link

gauthierbuttez commented Mar 7, 2024

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?

@nkinapsg
Copy link

did you find a solution yet?

@KashitsynArtem
Copy link

KashitsynArtem commented Mar 22, 2024

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

@iGwyn
Copy link

iGwyn commented May 31, 2024

did you find a solution yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants