crawl4ai icon indicating copy to clipboard operation
crawl4ai copied to clipboard

[Bug]: create_profile - Cross-platform compatibility issue

Open prokopis3 opened this issue 6 months ago • 2 comments

crawl4ai version

0.6.3

Expected Behavior

should work on both Unix and Windows systems.

Image

Current Behavior

user cannot press 'q' to exit

Is this reproducible?

No

Inputs Causing the Bug

The `listen_for_quit_command` function is designed to listen for terminal input and waits for the user to press `q`. However, this implementation uses Unix-specific libraries (`termios`, `tty`, `select`), which makes it incompatible with Windows systems.

Steps to Reproduce

- Run the code on a Windows machine.
- Observe that it fails due to missing Unix-specific libraries.

Code snippets


OS

Windows

Python version

3.12.3

Browser

Chromium

Browser version

Version 131.0.6778.33 (Official Build) (64-bit)

Error logs & Screenshots (if applicable)

Image

In the bug report, I initially selected "No" for the question "Is this reproducible?" — which may seem misleading. What I meant was that the issue was not reproducible under normal circumstances.

However, upon further investigation, I discovered that the bug is consistently reproducible, but only after applying the following commits/fixes:

33a0c7a da8f0db

These changes seem to introduce or expose the issue reliably. So technically, the bug is reproducible, just not in the unpatched/base version.

prokopis3 avatar May 30 '25 04:05 prokopis3

Apologies! Here's the code snippet. I'm running this on Windows PowerShell

import asyncio
from colorama import Fore, Style, init
from crawl4ai import AsyncLogger, BrowserProfiler


# Initialize colorama
init()

# Create a shared logger instance
logger = AsyncLogger(verbose=True)


# Create a shared BrowserProfiler instance
profiler = BrowserProfiler(logger=logger)


async def main():
    logger.info(
        f"{Fore.CYAN}Identity-Based Browsing Example with Crawl4AI{Style.RESET_ALL}",
        tag="DEMO",
    )
    logger.info(
        "This example demonstrates using profiles for authenticated browsing",
        tag="DEMO",
    )

    # Choose between interactive mode and automatic mode
    mode = input(
        f"{Fore.CYAN}Run in [i]nteractive mode or [a]utomatic mode? (i/a): {Style.RESET_ALL}"
    ).lower()

    if mode == "i":
        # Interactive profile management - use the interactive_manager method
        # Pass the crawl_with_profile function as the callback for the "crawl a website" option
        await profiler.interactive_manager()
    else:
        # Automatic mode - simplified example
        profiles = profiler.list_profiles()

        if not profiles:
            # Create a new profile if none exists
            logger.info("No profiles found. Creating a new one...", tag="DEMO")
            profile_path = await profiler.create_profile()
            if not profile_path:
                logger.error("Cannot proceed without a valid profile", tag="DEMO")
                return
        else:
            # Use the first (most recent) profile
            profile_path = profiles[0]["path"]
            logger.info(
                f"Using existing profile: {Fore.CYAN}{profiles[0]['name']}{Style.RESET_ALL}",
                tag="DEMO",
            )


if __name__ == "__main__":
    try:
        # Run the async main function
        asyncio.run(main())
    except KeyboardInterrupt:
        logger.warning("Example interrupted by user", tag="DEMO")
    except Exception as e:
        logger.error(f"Error in example: {str(e)}", tag="DEMO")

prokopis3 avatar May 30 '25 05:05 prokopis3

For context, another user shared similar issue in another repository in a duplicate issue. Adding it here for reference https://github.com/lesspass/lesspass/issues/556

aravindkarnam avatar May 30 '25 07:05 aravindkarnam

already merged with the main branch and the latest version (0.7.4)

ntohidi avatar Aug 18 '25 03:08 ntohidi