Skip to content

Sometimes cookies in the browser are not updated, but accumulate (requests are made with cookies with duplicate names). #329

@depis13

Description

@depis13

Sometimes cookies in the browser are not updated, but accumulate (requests are made with cookies with duplicate names). Because of this, for example, when entering the sales navigator with the choice of contract, one of the requests always gives http 400, although in the usual selenium and other similar tools this request is made normally and does not give an http error. If you copy this request through this tool as curl, you will see that, unlike normal requests from other tools, it contains cookies with duplicate names.
This is the only place where I found this bug. Unfortunately, it will be difficult to reproduce in this particular place, since a linkedin account with a sales navigator subscription is required. This happens when, using only a regular LinkedIn session, you log into sales navigator and the site gives you the cookies necessary for sales navigator.

from selenium_driverless import webdriver
from selenium_driverless.types.by import By

async def add_cookies(
    driver: webdriver.Chrome,
    cookies: list[dict],
) -> None:
    for cookie in cookies:
        await driver.add_cookie(cookie )
    await driver.refresh()

@asynccontextmanager
async def create_driver(self, proxy: Proxy) -> AsyncIterator[webdriver.Chrome]:
    options = webdriver.ChromeOptions()
    # options.add_argument("--headless=new")
    options.add_argument("--no-sandbox")
    options.add_argument("--lang=en")
    async with webdriver.Chrome(options=options) as driver:
        yield driver

async def async_get_sales_navigator_cookies(
    common_cookies: list[dict],
) -> list[Cookie]:
    async with create_driver(proxy=proxy) as driver:
          await driver.get("https://www.linkedin.com/", wait_load=True)
          await add_cookies(driver=driver, cookies=common_cookies)
          input('test')
          await driver.get("https://www.linkedin.com/sales/home", wait_load=True)
          await driver.find_element(
              By.CSS_SELECTOR,
              '[data-control-name="view_user_menu_from_app_header"]',
              timeout=30,
          )
with open("cookies.json", "r") as file:
    cookies_dicts = json.load(file)
asyncio.run(async_get_sales_navigator_cookies(cookies_dicts)


Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions