Files
schwab-mcp-custom/schwab_scraper/browser/client.py
b3nw 650ea2d087
All checks were successful
Build and Push Docker Image / build (push) Successful in 34s
Fix build: Bundle schwab_scraper source and use local dependencies
2026-04-24 01:50:20 +00:00

31 lines
1.0 KiB
Python

from typing import Any
from playwright.async_api import async_playwright
async def connect(playwright_url: str):
p = await async_playwright().start()
browser = await p.chromium.connect(playwright_url)
return p, browser
async def new_context(browser, cookies: list[dict] | None = None, user_agent: str | None = None):
context = await browser.new_context(
user_agent=user_agent or 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36'
)
if cookies:
valid_same_site_values = ['Strict', 'Lax', 'None']
for cookie in cookies:
if cookie.get('sameSite') not in valid_same_site_values:
if cookie.get('sameSite') == 'no_restriction':
cookie['sameSite'] = 'None'
else:
cookie['sameSite'] = 'Lax'
await context.add_cookies(cookies) # type: ignore
return context
async def new_page(context):
return await context.new_page()