Automating Browser Sessions
This skill covers browser automation for accounts and sites you own or have explicit permission to automate. It does not cover intercepting another person's messages, defeating ephemeral/"view-once" content protections, or getting any system to bypass ToS review "without concern." Those requests aren't included here regardless of framing — build around your own account, your own session, your own consent.
If what you actually need is to export your own Messenger data or build a bot you operate, see "Legitimate alternatives" below.
Pythonfrom playwright.sync_api import sync_playwright with sync_playwright() as p: browser = p.chromium.launch(headless=False) context = browser.new_context(storage_state="my_auth_state.json") # your saved session page = context.new_page() page.goto("https://example.com/account") print(page.title()) browser.close()
Run once manually to log in and save state:
Pythoncontext = browser.new_context() page = context.new_page() page.goto("https://example.com/login") input("Log in manually, then press Enter...") context.storage_state(path="my_auth_state.json")
Progress:
- Step 1: Identify the account/site — confirm you own it or have written permission to automate it
- Step 2: Capture session state once via manual login (
storage_state) - Step 3: Write the automation script against that saved state
- Step 4: Add explicit waits/selectors instead of fixed sleeps
- Step 5: Run headless in background (cron, systemd timer, or Task Scheduler)
- Step 6: Log actions taken for your own audit trail
Step 1: Confirm scope
Only automate accounts you control. If the target is a third-party platform's TOS-restricted feature (message interception, disappearing content, someone else's inbox), stop — that's out of scope for this skill.
Step 2: Capture session
Pythoncontext.storage_state(path="auth.json")
Store this file securely (treat like a password). Re-run the manual login step when it expires.
Step 3: Script the task
Use Playwright locators, not raw CSS guesses:
Pythonpage.get_by_role("button", name="Export my data").click() page.wait_for_selector("text=Export ready")
Step 4: Background execution
Bash# cron example: run every hour 0 * * * * /usr/bin/python3 /home/user/export_job.py >> /home/user/export.log 2>&1
Step 5: Handle data responsibly
Save fetched data locally, encrypt if sensitive, and never forward content belonging to other people without their knowledge.
Example 1: Automated data export from your own account
Input: You want a nightly export of your own order history from a shopping site.
Output: A Playwright script that loads auth.json, navigates to /account/orders, scrapes the table into orders.csv, and is scheduled via cron.
Example 2: Monitoring your own listing status
Input: You want to check every 30 minutes whether your own marketplace listing is still active.
Output: A headless script using saved session state that checks for a text=Active badge and sends you (not anyone else) a Telegram/email alert on change.
- Official data export: Meta provides "Download Your Information" for your own account — automate the request, not the interception, via your own authenticated session.
- Bot/integration: Use the official Meta Messenger Platform API with a registered app and proper OAuth — not browser automation — for sending/receiving messages programmatically.
- Archiving your own sent/received media: Only via platform-provided export tools; "view-once" content is intentionally excluded from export by design and isn't a target here.
- Prefer official APIs over browser automation whenever the platform offers one
- Store
storage_statefiles outside version control, encrypted at rest - Use explicit selectors (
get_by_role,get_by_text) over brittle XPath/CSS - Rate-limit background jobs to avoid tripping anti-bot protections
- Log every automated action for your own accountability
- Don't hardcode credentials in scripts — use saved session state or environment-injected secrets
- Don't run automation against accounts/features you don't have permission to script
- Don't try to work around a platform's deliberate design (e.g., ephemeral content not being exportable) — that's a signal the data isn't meant to be captured
- Don't scale personal scripts into always-on scrapers of other users' content