[Python] Why localStorage.getItem given none?

Discussão em 'Python' iniciado por Stack, Março 29, 2025.

  1. Stack

    Stack Membro Participativo

    why return window.localStorage.getItem always given none ? Even though when you see it there is value.

    import undetected_chromedriver as webdriver
    import time


    recreate_localStorage_script = '''
    const iframe = document.createElement('iframe');
    document.head.append(iframe);
    const pd = Object.getOwnPropertyDescriptor(iframe.contentWindow, 'localStorage');
    iframe.remove();
    Object.defineProperty(window, 'localStorage', pd);
    '''

    options = webdriver.ChromeOptions()
    profile = "C:\\Users\\nicvaldy\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 38"
    options.add_argument(f"user-data=dir={profile}",)
    mobile_emulation = {
    "deviceMetrics": { "width": 360, "height": 640, "pixelRatio": 3.0 },
    "userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile Safari/535.19" }
    chrome_options = webdriver.ChromeOptions()

    chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)

    driver = webdriver.Chrome(options=options,use_subprocess=True)
    driver.get("https://click.discord.com/ls/click?xxxxxxxxxxxxxxxx")
    driver.execute_script(recreate_localStorage_script)
    print(driver.execute_script(f"return window.localStorage.getItem('token');"))


    [​IMG]

    [​IMG]

    please help me to solve this problem, thanks

    Continue reading...

Compartilhe esta Página