scitex_browser.collaboration

scitex_browser.collaboration - Interactive browser automation for AI-human teams.

This is a NEW module that does NOT affect existing scitex.browser functionality.

Features: - Persistent shared browser sessions - Multi-agent coordination - AI-human collaboration - Authentication handling - Content extraction

Version: 0.1.0-alpha (experimental)

class scitex_browser.collaboration.SharedBrowserSession(config=None)[source]

Bases: object

Persistent browser session shared between AI agents and humans.

Simple, incremental start - just the basics.

Example

# Start session session = SharedBrowserSession() await session.start()

# Navigate await session.navigate(”http://127.0.0.1:8000”)

# Take screenshot screenshot = await session.screenshot()

# Keep running await session.wait()

# Close when done await session.close()

__init__(config=None)[source]

Initialize shared session.

async start()[source]

Start the persistent browser session.

Uses persistent context pattern from ScholarBrowserManager.

async navigate(url, wait_until='load', timeout=60000)[source]

Navigate to URL.

Parameters:
  • url (str) – URL to navigate to

  • wait_until (str) – “load”, “domcontentloaded”, or “networkidle” (default: “load”)

  • timeout (int) – Timeout in milliseconds (default: 60000)

Return type:

str

Returns:

Current URL after navigation

async screenshot(message='')[source]

Take screenshot and save to scitex.capture directory.

Return type:

str

Returns:

Path to screenshot file

async wait(duration=None)[source]

Wait for duration or until stopped.

Parameters:

duration (Optional[float]) – Seconds to wait, or None to wait indefinitely

async close()[source]

Close the session.

async __aenter__()[source]

Context manager entry.

async __aexit__(*args)[source]

Context manager exit.

_log_event(event_type, data)[source]

Simple event logging.

async _auto_screenshot_loop()[source]

Automatically take screenshots at intervals.

get_info()[source]

Get session information.

Return type:

dict

async type(selector, text, delay=50)[source]

Type text like a human (with delay between keys).

async click(selector)[source]

Click element.

async hover(selector)[source]

Hover over element.

async press(key)[source]

Press keyboard key (Enter, Tab, Escape, etc.).

async scroll_down(amount=500)[source]

Scroll down.

async scroll_to(selector)[source]

Scroll element into view.

async wait_for(selector, timeout=5000)[source]

Wait for element to appear.

async wait_for_text(text, timeout=5000)[source]

Wait for text to appear.

async wait_for_url(pattern, timeout=5000)[source]

Wait for URL to match pattern.

async get_text(selector)[source]

Get text content of element.

Return type:

str

async get_value(selector)[source]

Get value of input element.

Return type:

str

async is_visible(selector)[source]

Check if element is visible.

Return type:

bool

async ask(question, options=None)[source]

Ask user a question in the browser.

Returns user’s response.

Example

response = await session.ask(“What username to use?”) response = await session.ask(“Choose:”, [“Option A”, “Option B”])

Return type:

str

async confirm(message)[source]

Ask user for confirmation in browser.

Returns True if user clicks OK, False if Cancel.

Return type:

bool

class scitex_browser.collaboration.SessionConfig(session_id='default', browser_type='chromium', headless=False, viewport=<factory>, user_data_dir=None, enable_screenshots=True, screenshot_interval=None)[source]

Bases: object

Configuration for shared browser session.

session_id: str = 'default'
browser_type: str = 'chromium'
headless: bool = False
viewport: dict
user_data_dir: str | None = None
enable_screenshots: bool = True
screenshot_interval: float | None = None
__init__(session_id='default', browser_type='chromium', headless=False, viewport=<factory>, user_data_dir=None, enable_screenshots=True, screenshot_interval=None)
class scitex_browser.collaboration.VisualFeedback(page)[source]

Bases: object

Simple visual feedback overlay on browser.

Shows: - Who’s in control - What action is being performed - Status messages

__init__(page)[source]
async initialize()[source]

Initialize visual feedback overlay.

async show_message(message, type='info', duration=3000)[source]

Show feedback message.

async show_participant(name, type='agent')[source]

Show participant indicator.

async show_action(participant_name, action)[source]

Show what participant is doing.

async clear()[source]

Clear all feedback.

class scitex_browser.collaboration.CredentialManager(verbose=True)[source]

Bases: object

Flexible credential retrieval.

Tries multiple sources in order: 1. Explicitly provided credentials 2. Environment variables 3. Terminal prompt (if terminal available) 4. Browser prompt (if browser available)

Always clearly communicates what it’s doing!

__init__(verbose=True)[source]
async get_credential(name, env_var=None, prompt_text=None, page=None, mask=False)[source]

Get credential from best available source.

Parameters:
  • name (str) – Credential name (for caching)

  • env_var (Optional[str]) – Environment variable to check

  • prompt_text (Optional[str]) – Text to show in prompt

  • page (Optional[Page]) – Playwright page (for browser prompts)

  • mask (bool) – Whether to mask input (for passwords)

Return type:

str

Returns:

Credential value

Example

username = await creds.get_credential(

name=”username”, env_var=”SCITEX_CLOUD_USERNAME”, prompt_text=”Django username”, page=page,

)

_is_terminal_available()[source]

Check if we can prompt in terminal.

Return type:

bool

async _prompt_terminal(name, prompt_text, mask)[source]

Prompt user in terminal.

Return type:

Optional[str]

async _prompt_browser(page, name, prompt_text)[source]

Prompt user in browser window.

Return type:

Optional[str]

async get_login_credentials(page=None, username_env='SCITEX_CLOUD_USERNAME', password_env='SCITEX_CLOUD_PASSWORD')[source]

Get both username and password.

Convenient helper for login flows.

Returns:

‘…’, ‘password’: ‘…’}

Return type:

{‘username’

clear_cache()[source]

Clear credential cache.

class scitex_browser.collaboration.GoogleAuthHelper(email=None, password=None, debug=False)[source]

Bases: object

Google OAuth authentication helper.

Handles the popup-based Google OAuth flow used by many services.

Environment Variables:

GOOGLE_EMAIL: Default email if not provided GOOGLE_PASSWORD: Default password if not provided

__init__(email=None, password=None, debug=False)[source]

Initialize GoogleAuthHelper.

Parameters:
  • email (Optional[str]) – Google account email

  • password (Optional[str]) – Google account password

  • debug (bool) – Print debug messages to stderr

_log(msg)[source]

Print debug message if debug mode is enabled.

async login_via_google_button(page, google_button_selector='button:has-text("Continue with Google")', timeout=60000)[source]

Perform Google OAuth login via a “Continue with Google” button.

This handles the popup-based OAuth flow: 1. Click the Google button on the main page 2. Handle the Google popup for email/password entry 3. Wait for redirect back to the original service

Parameters:
  • page (Page) – Playwright Page object (the main page with the Google button)

  • google_button_selector (str) – CSS selector for the Google login button

  • timeout (int) – Maximum time to wait for login (ms)

Return type:

bool

Returns:

True if login successful, False otherwise

async _handle_google_popup(popup, timeout=60000)[source]

Handle the Google OAuth popup flow.

Parameters:
  • popup (Page) – The Google OAuth popup page

  • timeout (int) – Maximum time to wait (ms)

Return type:

bool

Returns:

True if authentication successful, False otherwise

async _fill_email(popup)[source]

Fill email on Google login page.

Return type:

bool

async _fill_password(popup)[source]

Fill password on Google login page.

Return type:

bool

Handle OAuth consent or ‘Continue’ screens that may appear.

Return type:

None

async _wait_for_2fa(popup, timeout=60000)[source]

Wait for 2FA verification to complete.

Detects 2FA screens and waits for user to approve on their device.

Parameters:
  • popup (Page) – The Google OAuth popup page

  • timeout (int) – Maximum time to wait for 2FA (ms)

Return type:

bool

Returns:

True if 2FA completed, False if timed out

async is_logged_in(page, login_indicators=None)[source]

Check if user appears to be logged in.

Parameters:
  • page (Page) – Page to check

  • login_indicators (list) – List of URL substrings that indicate NOT logged in (default: [“login”, “signin”, “oauth”])

Return type:

bool

Returns:

True if appears logged in, False otherwise

async scitex_browser.collaboration.google_login(page, email, password, button_selector='button:has-text("Continue with Google")', debug=False)[source]

Quick Google OAuth login.

Parameters:
  • page (Page) – Playwright Page with Google login button

  • email (str) – Google account email

  • password (str) – Google account password

  • button_selector (str) – CSS selector for Google button

  • debug (bool) – Print debug messages

Return type:

bool

Returns:

True if login successful, False otherwise

Example

success = await google_login(page, “user@gmail.com”, “password”)