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

Add option to select which browser playwright uses #1129

Merged
merged 3 commits into from
Apr 12, 2024
Merged
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
24 changes: 15 additions & 9 deletions TikTokApi/tiktok.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ async def create_sessions(
override_browser_args: list[dict] = None,
cookies: list[dict] = None,
suppress_resource_load_types: list[str] = None,
browser: str = "chromium",
executable_path: str = None
):
"""
Expand All @@ -231,6 +232,7 @@ async def create_sessions(
override_browser_args (list[dict]): A list of dictionaries containing arguments to pass to the browser.
cookies (list[dict]): A list of cookies to use for the sessions, you can get these from your cookies after visiting TikTok.
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

Example Usage:
.. code-block:: python
Expand All @@ -240,15 +242,19 @@ async def create_sessions(
await api.create_sessions(num_sessions=5, ms_tokens=['msToken1', 'msToken2'])
"""
self.playwright = await async_playwright().start()
if headless and override_browser_args is None:
override_browser_args = ["--headless=new"]
headless = False # managed by the arg
self.browser = await self.playwright.chromium.launch(
headless=headless,
args=override_browser_args,
proxy=random_choice(proxies),
executable_path=executable_path
)
if browser == "chromium":
if headless and override_browser_args is None:
override_browser_args = ["--headless=new"]
headless = False # managed by the arg
self.browser = await self.playwright.chromium.launch(
headless=headless, args=override_browser_args, proxy=random_choice(proxies), executable_path=executable_path
)
elif browser == "firefox":
self.browser = await self.playwright.firefox.launch(
headless=headless, args=override_browser_args, proxy=random_choice(proxies), executable_path=executable_path
)
else:
raise ValueError("Invalid browser argument passed")

await asyncio.gather(
*(
Expand Down