Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: playwright timeout sessions with provide opt-out params #1196

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

Expand Down Expand Up @@ -213,7 +217,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 @@ -234,6 +239,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 @@ -271,6 +277,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