-
Notifications
You must be signed in to change notification settings - Fork 95
Open
Description
This script successfully logins into Facebook, bypassing all their automation detection. However, after submitting the login, it appears to encounter a 2FA/captcha screen. Unfortunately, there's something in stealth that's breaking the JS, because the browser JS console shows that a ton of Facebook JS scripts aren't able to load. This results in the 2FA page being blank (except for a Facebook header).
import os
import time
import argparse
from playwright.sync_api import sync_playwright
from playwright_stealth import stealth_sync
import random
# Show the browser (set to False to run headless)
SHOW = True
URL = 'https://www.facebook.com'
# Path to the Brave browser executable
BRAVE_PATH = '/usr/bin/brave-browser' # Update this path as needed
def human_delay(min_delay=0.2, max_delay=0.6):
time.sleep(random.uniform(min_delay, max_delay))
def main():
parser = argparse.ArgumentParser(description="Launch browser and log into a site")
args = parser.parse_args()
username = os.getenv("LOGIN_USERNAME")
password = os.getenv("LOGIN_PASSWORD")
if not username or not password:
print("❌ LOGIN_USERNAME and LOGIN_PASSWORD environment variables must be set.")
return
with sync_playwright() as p:
browser = p.chromium.launch(
headless=not SHOW,
executable_path=BRAVE_PATH,
args=["--disable-blink-features=AutomationControlled"]
)
ua = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
context = browser.new_context(
user_agent=ua,
extra_http_headers={
"Accept-Language": "en-US,en;q=0.9"
}
)
page = context.new_page()
stealth_sync(page)
print(f"Navigating to {URL}...")
response = page.goto(URL)
if response and response.status == 200:
print("✅ Page loaded successfully")
try:
email_field = page.locator("input[name='email']").first
pass_field = page.locator("input[name='pass']").first
email_field.click()
for char in username:
email_field.type(char)
human_delay(0.05, 0.15)
human_delay(0.5, 1.0)
pass_field.click()
for char in password:
pass_field.type(char)
human_delay(0.05, 0.15)
human_delay(0.5, 1.5)
page.keyboard.press("Enter")
print("🔐 Login form submitted")
except Exception as e:
print(f"⚠️ Could not interact with login form: {e}")
else:
print("❌ Failed to load the page.")
print("🕒 Browser will stay open. Press CTRL+C to quit.")
try:
while True:
pass # Keep script alive
except KeyboardInterrupt:
print("👋 Exiting...")
context.close()
browser.close()
if __name__ == '__main__':
main()
Screenshot of the browser after login:
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
