Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Can't access websites when loading user data #3956

Answered by mdmintz
hentg089 asked this question in Q&A
Discussion options

If you look at the following simple code:

from seleniumbase import Driver
import time

user_data_dir = r"C:\Users\markh\AppData\Local\Google\Chrome\User Data"

driver = Driver(uc=True, user_data_dir=user_data_dir)

try:
driver.get("https://www.tiktok.com")

time.sleep(10)

finally:
# Always close the browser when done
driver.quit()

Tiktok will always run whne I don't pass the user data in but when I start passing hte user data such that I'm logged in as a profile, tiktok or any other site for that matter refuse to load

You must be logged in to vote

You can't mix a UC Mode user_data_dir with one that was used by a regular Chrome instance. The formats are different.

Have UC Mode create a new user_data_dir during the script run, and then you can call the script again with the same one.

Here's an example of a script that goes to TikTok while setting a custom user_data_dir:

from seleniumbase import SB
with SB(uc=True, test=True, ad_block=True, user_data_dir="my_dir") as sb:
 url = "https://www.tiktok.com/@startrek?lang=en"
 sb.activate_cdp_mode(url)
 sb.sleep(2)
 print(sb.get_text('h2[data-e2e="user-bio"]'))
 for i in range(54):
 sb.cdp.scroll_down(12)
 sb.sleep(1)

Replies: 1 comment 4 replies

Comment options

You can't mix a UC Mode user_data_dir with one that was used by a regular Chrome instance. The formats are different.

Have UC Mode create a new user_data_dir during the script run, and then you can call the script again with the same one.

Here's an example of a script that goes to TikTok while setting a custom user_data_dir:

from seleniumbase import SB
with SB(uc=True, test=True, ad_block=True, user_data_dir="my_dir") as sb:
 url = "https://www.tiktok.com/@startrek?lang=en"
 sb.activate_cdp_mode(url)
 sb.sleep(2)
 print(sb.get_text('h2[data-e2e="user-bio"]'))
 for i in range(54):
 sb.cdp.scroll_down(12)
 sb.sleep(1)
You must be logged in to vote
4 replies
Comment options

This didn't work. I threw print statements inside of the with block and none of them ever printed. I was able to get chrome to open with the correct account signed in but it never navigated to tiktok

Comment options

There would be a stack trace if it didn't reach the print() statements inside the with block.

Comment options

Screenshot 2025年09月03日 172542 Here's the image. You can see it was able to open chrome with the account but only the first print comes out...
Comment options

You can't mix a UC Mode user_data_dir with one that was used by a regular Chrome instance. The formats are different. I can see you're setting the user_data_dir to the one from your regular Chrome browser.

Answer selected by mdmintz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /