| |
| import asyncio |
| import time |
| from playwright.async_api import async_playwright |
|
|
| class BypassUV: |
| def __init__(self): |
| self.browser = None |
| self.pw = None |
| self.semaphore = asyncio.Semaphore(5) |
|
|
| async def start(self): |
| self.pw = await async_playwright().start() |
|
|
| self.browser = await self.pw.chromium.launch( |
| headless=True, |
| args=[ |
| "--no-sandbox", |
| "--disable-setuid-sandbox", |
| "--disable-blink-features=AutomationControlled", |
| "--disable-dev-shm-usage", |
| "--disable-gpu" |
| ] |
| ) |
|
|
| async def stop(self): |
| if self.browser: |
| await self.browser.close() |
| if self.pw: |
| await self.pw.stop() |
|
|
| async def bypass(self, url: str): |
| async with self.semaphore: |
| start = time.perf_counter() |
|
|
| context = await self.browser.new_context( |
| user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64)", |
| locale="en-US", |
| timezone_id="Asia/Ho_Chi_Minh", |
| java_script_enabled=True, |
| ignore_https_errors=True |
| ) |
|
|
| page = await context.new_page() |
|
|
| try: |
| await page.goto(url, wait_until="domcontentloaded", timeout=20000) |
|
|
| |
| await page.goto( |
| "https://userscript.baconbypass.online/load-cf", |
| wait_until="domcontentloaded", |
| timeout=20000 |
| ) |
|
|
| |
| token = await page.evaluate( |
| """() => new Promise(resolve => { |
| window.addEventListener("message", e=>{ |
| if(e.data && (e.data.type==="CF_SOLVED" || e.data.type==="TURNSTILE_SOLVED")){ |
| resolve(e.data.token) |
| } |
| }) |
| })""" |
| ) |
|
|
| |
| result = await page.evaluate( |
| """async (url, token)=>{ |
| const r = await fetch("https://userscript.baconbypass.online/adlink",{ |
| method:"POST", |
| headers:{'Content-Type':'application/json'}, |
| body:JSON.stringify({url:url,token:token}) |
| }) |
| return await r.json() |
| }""", |
| url, |
| token |
| ) |
|
|
| processed = round(time.perf_counter() - start, 2) |
|
|
| if result.get("status") == "success": |
| return { |
| "ok": True, |
| "result": result.get("result"), |
| "processed": f"{processed}s" |
| } |
|
|
| return { |
| "ok": False, |
| "error": result, |
| "processed": f"{processed}s" |
| } |
|
|
| except Exception as e: |
|
|
| processed = round(time.perf_counter() - start, 2) |
|
|
| return { |
| "ok": False, |
| "error": str(e), |
| "processed": f"{processed}s" |
| } |
|
|
| finally: |
| await context.close() |