Skip to content

Commit

Permalink
fix: playwright timeout sessions with provide opt-out params when cre…
Browse files Browse the repository at this point in the history
…ating sessions (#1196)
  • Loading branch information
arhen authored Jan 21, 2025
1 parent 9d3ed1e commit 77f4e4e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion TikTokApi/tiktok.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ async def __create_session(
sleep_after: int = 1,
cookies: dict = None,
suppress_resource_load_types: list[str] = None,
timeout: int = 300000,
):
"""Create a TikTokPlaywrightSession"""
if ms_token is not None:
Expand Down Expand Up @@ -177,6 +178,9 @@ def handle_request(request):
if request.resource_type in suppress_resource_load_types
else route.continue_(),
)

# Set the navigation timeout
page.set_default_navigation_timeout(timeout)

await page.goto(url)
await page.goto(url) # hack: tiktok blocks first request not sure why
Expand Down Expand Up @@ -214,7 +218,8 @@ async def create_sessions(
cookies: list[dict] = None,
suppress_resource_load_types: list[str] = None,
browser: str = "chromium",
executable_path: str = None
executable_path: str = None,
timeout: int = 300000,
):
"""
Create sessions for use within the TikTokApi class.
Expand All @@ -235,6 +240,7 @@ async def create_sessions(
suppress_resource_load_types (list[str]): Types of resources to suppress playwright from loading, excluding more types will make playwright faster.. Types: document, stylesheet, image, media, font, script, textrack, xhr, fetch, eventsource, websocket, manifest, other.
browser (str): specify either firefox or chromium, default is chromium
executable_path (str): Path to the browser executable
timeout (int): The timeout in milliseconds for page navigation
Example Usage:
.. code-block:: python
Expand Down Expand Up @@ -272,6 +278,7 @@ async def create_sessions(
sleep_after=sleep_after,
cookies=random_choice(cookies),
suppress_resource_load_types=suppress_resource_load_types,
timeout=timeout,
)
for _ in range(num_sessions)
)
Expand Down

0 comments on commit 77f4e4e

Please sign in to comment.