ShardBrowser
ShardBrowser copied to clipboard
[BUG] Shardx().delete_profile() Does Not Work
After the last update, SDK.delete_profile() no longer has any effect, and profiles stay saved on my device.
Environment
Platform: Windows 11 Source: Python SDK v2.1.7 (latest)
Example Code:
from platform import system
from shardx import ShardX, Motion
from patchright.async_api import Page, TimeoutError, Route
from contextlib import suppress
import asyncio
import random
SDK = ShardX()
# TEST_URL = "https://m.weibo.com/"
# TEST_SELECTOR = ".wb-item-wrap"
# async def hover_to_el(page: Page, motion: Motion, selector: str, nth: int | str="random"):
# """Realistic hovering to the element using Shard's Motion object."""
# page_height = await page.evaluate(r'() => {return window.innerHeight;}')
# if isinstance(nth, int):
# el = page.locator(selector).nth(nth)
# else:
# els = await page.query_selector_all(selector)
# els_count = len(els)
# el = page.locator(selector).nth(random.randint(0, els_count - 1))
# box = await el.bounding_box()
# # If the element is below the screen, scroll down to it
# if box["y"] > page_height:
# await motion.wheel(delta_y=(box["y"] - page_height) + random.uniform(0.15, 0.4) * box["height"])
# box = await el.bounding_box()
# elif box["y"] < 0: # If the element is above the screen, scroll up to it
# await motion.wheel(delta_y=box["y"] - random.uniform(0.15, 0.4) * box["height"])
# box = await el.bounding_box()
# # Once sure that the element is in view, hover to it
# await motion.glide_to(
# x=box["x"] + random.uniform(0.4, 0.6) * box["width"],
# y=box["y"] + random.uniform(0.4, 0.6) * box["height"],
# target_width=box["width"]
# )
async def main():
profile = SDK.create_profile(platform="Windows").with_override(
timezone="auto",
navigator={"language": "auto"},
geolocation={"mode": "auto"}
)
try:
async with SDK.session(profile, headless=True) as browser:
page = browser.contexts[0].pages[0]
# await page.route("**/*", block_images)
await page.goto("https://www.google.com/", wait_until="domcontentloaded")
finally:
ids = SDK.list_saved_profiles()
for id_ in ids:
SDK.delete_profile(id_)
if __name__ == "__main__":
asyncio.run(main())
This code used to go to google.com and then delete all the saved profiles at the end. After the last update, SDK.delete_profile() is completely ignored, and all profiles remain saved on my computer and don't get deleted.