Home
Softono
browser2api

browser2api

Open source Python
16
Stars
3
Forks
1
Issues
0
Watchers
3 months
Last Commit

About browser2api

Turn browser UIs into programmatic image and video generation APIs. Automates image generation tools such as Jimeng (即梦AI) and Google Flow via Playwright + Chrome CDP — no API keys or reverse engineering needed.

Platforms

Web Self-hosted

Languages

Python

Links

browser2api

Turn browser UIs into programmatic image and video generation APIs.

Automates web UIs via Playwright + Chrome CDP — no API keys or reverse engineering needed.

Python 3.11+ Playwright Chrome CDP

English | 中文


Supported Platforms

Jimeng Jimeng (即梦AI)

Image: Seedream 5.0 — up to 4 images, 2K/4K
Video: Seedance 2.0 — 5s/10s, up to 1080p

Google Google Flow

Image: Imagen 4, Nano Banana 2 — up to 4 images
Video: Veo 3.1 — Fast / Quality

Demo

Jimeng — Image Generation with Seedream 5.0 · "A Shiba Inu eating ramen in a ramen shop, anime style"

https://github.com/user-attachments/assets/616f7f5f-1b20-49dd-9579-4680f310a32b

Google Flow — Image Generation with Nano Banana 2 · "Shiba eating ramen, anime style"

https://github.com/user-attachments/assets/8df63cf4-a429-48df-a26d-74be0c23b7e5

Google Flow — Video Generation with Veo 3.1 Fast · "A cat walking through a garden"

https://github.com/user-attachments/assets/7b69ccf4-4824-4bff-adca-11dfc12fcbbf

Setup

python3 -m venv .venv
source .venv/bin/activate
pip install -e .
playwright install chromium

Requires Python 3.11+ and Google Chrome installed locally.

Quick Start

Jimeng — Image Generation

python examples/generate.py "A cat in an astronaut suit standing on the moon"
python examples/generate.py "prompt" --model jimeng-5.0 --ratio 1:1 --resolution "超清 4K"

Models: jimeng-3.0 jimeng-3.1 jimeng-4.0 jimeng-4.1 jimeng-4.5 jimeng-4.6 jimeng-5.0

Jimeng — Video Generation

python examples/generate_video.py "A cat walking through a garden"
python examples/generate_video.py "City night skyline" --ratio 16:9 --duration 10s --model video-3.0-fast

Models: seedance-2.0-fast seedance-2.0 video-3.5-pro video-3.0-pro video-3.0-fast video-3.0

Google Flow — Image Generation

python examples/generate_flow.py "A sunset over mountains, digital art"
python examples/generate_flow.py "prompt" --model nano-banana-2 --orientation portrait --count 4

Models: nano-banana-pro nano-banana-2 imagen-4

Google Flow — Video Generation

python examples/generate_flow_video.py "A cat walking through a garden"
python examples/generate_flow_video.py "prompt" --model veo-3.1-quality --orientation portrait --count 1

Models: veo-3.1-fast veo-3.1-quality veo-2-fast veo-2-quality

How It Works

  1. Launch — Opens a real Chrome browser via CDP (not Playwright's bundled Chromium) for anti-detection
  2. Login — Checks for a valid session. If not logged in, opens a headed browser for manual login. Session persists in ~/.browser2api/browser_data/
  3. Generate — Navigates to the generation page, configures model/settings via UI automation, fills the prompt, clicks submit
  4. Capture — Intercepts network responses and polls the DOM for generated content
  5. Download — Downloads results locally

Programmatic Usage

import asyncio
from browser2api import BrowserManager, Platform
from browser2api.platforms.jimeng import JimengClient, JimengModel, JimengRatio

async def main():
    bm = BrowserManager()
    context, page = await bm.launch_for_login(Platform.JIMENG)

    client = JimengClient(
        page, context,
        output_dir="./output",
        model=JimengModel.JIMENG_5_0,
        ratio=JimengRatio.RATIO_1_1,
    )

    result = await client.generate_images("一只猫", count=4, timeout_seconds=120)
    print(f"Status: {result.status.value}")
    for img in result.images:
        print(f"  {img.local_path} ({img.width}x{img.height})")

    await bm.close()

asyncio.run(main())
from browser2api.platforms.flow import FlowVideoClient, FlowVideoModel, FlowOrientation

async def generate_flow_video():
    bm = BrowserManager()
    context, page = await bm.launch_for_login(Platform.FLOW)

    client = FlowVideoClient(
        page, context,
        output_dir="./output",
        model=FlowVideoModel.VEO_3_1_FAST,
        orientation=FlowOrientation.LANDSCAPE,
    )

    result = await client.generate_video("A cat walking through a garden", timeout_seconds=300)
    print(f"Video: {result.video.local_path} ({result.video.size_bytes:,} bytes)")

    await bm.close()

Notes

Jimeng (即梦AI)

  • Member subscription recommended — Required for video generation and higher daily image quotas.
  • Login — First run opens a headed Chrome window for manual login. Session is saved and reused.
  • 4K resolution — Requires membership. Free accounts are limited to 2K.
  • Video generation — 30-120s depending on model/duration.

Google Flow

  • Google account required — Must be logged in via the headed browser.
  • Regional availability — May require a VPN in some regions.
  • Video generation — 60-120+s depending on model.

Project Structure

src/browser2api/
├── config.py              # Shared constants (DATA_DIR)
├── types.py               # Platform, GenerationStatus, GeneratedImage, GeneratedVideo, etc.
├── base.py                # Abstract base classes
├── browser.py             # BrowserManager, ChromeLauncher, CDP connection
└── platforms/
    ├── jimeng/
    │   ├── client.py      # JimengBaseClient, JimengClient, JimengVideoClient
    │   ├── enums.py       # Models, ratios, resolutions, durations
    │   ├── selectors.py   # CSS selectors and URL constants
    │   └── login.py       # Cookie-based login handler
    └── flow/
        ├── client.py      # FlowBaseClient, FlowClient, FlowVideoClient
        ├── enums.py       # Models, orientations, video models
        ├── selectors.py   # CSS selectors and URL constants
        └── login.py       # Login handler

Disclaimer

This project automates browser interactions with third-party platforms. Use at your own risk.

  • Rate limits — Avoid aggressive usage. Respect platform rate limits and credit quotas.
  • Session data — Stored locally in ~/.browser2api/. Keep this directory secure.
  • For personal/research use only — Do not use for commercial purposes or at scale without permission from the respective platforms.