unclecode/crawl4ai · error · ValueError

Profile not found: {profile_name_or_path}

Error message

Profile not found: {profile_name_or_path}

What it means

BrowserProfiler.shrink_profile(profile_name_or_path) resolves the argument against profiles_dir when relative, then requires the result to be an existing directory; otherwise ValueError('Profile not found: ...'). This is the class-method counterpart to the free function's check and does handle bare profile names — failure means neither <profiles_dir>/<name> nor the absolute path is a directory.

Source

Thrown at crawl4ai/browser_profiler.py:804

        """
        Shrink a profile to reduce storage while preserving authentication data.

        Args:
            profile_name_or_path: Profile name or full path
            level: LIGHT, MEDIUM, AGGRESSIVE (default), or MINIMAL
            dry_run: If True, only preview what would be removed

        Returns:
            Dict with 'removed', 'kept', 'bytes_freed', 'size_before', 'size_after', 'errors'
        """
        # Resolve path
        if os.path.isabs(profile_name_or_path):
            profile_path = profile_name_or_path
        else:
            profile_path = os.path.join(self.profiles_dir, profile_name_or_path)

        if not os.path.isdir(profile_path):
            raise ValueError(f"Profile not found: {profile_name_or_path}")

        result = shrink_profile(profile_path, level, dry_run)

        action = "Would free" if dry_run else "Freed"
        self.logger.info(
            f"{action} {_format_size(result['bytes_freed'])} "
            f"({len(result['removed'])} items removed, {len(result['kept'])} kept)",
            tag="SHRINK"
        )

        return result

    async def interactive_manager(self, crawl_callback=None):
        """
        Launch an interactive profile management console.
        
        Args:
            crawl_callback (callable, optional): Function to call when selecting option to use 

View on GitHub (pinned to 7e80152142)

Solutions

  1. List existing profiles first (BrowserProfiler().list_profiles()) and use an exact name.
  2. Pass the absolute path to the profile directory if it lives outside profiles_dir.
  3. Create the profile (profile flow) at least once before shrinking.

Example fix

# before
profiler.shrink_profile('my-profil', ShrinkLevel.MEDIUM)  # typo -> ValueError

# after
names = [p['name'] for p in profiler.list_profiles()]
assert 'my-profile' in names
profiler.shrink_profile('my-profile', ShrinkLevel.MEDIUM)
Defensive patterns

Strategy: validation

Validate before calling

import os
path = p if os.path.isabs(p) else os.path.join(profiler.profiles_dir, p)
if not os.path.isdir(path):
    raise ValueError(f'no such profile: {p} (searched {path})')

Type guard

import os
def profile_exists(profiler, name_or_path) -> bool:
    path = name_or_path if os.path.isabs(name_or_path) else os.path.join(profiler.profiles_dir, name_or_path)
    return os.path.isdir(path)

Try / catch

try:
    result = profiler.shrink_profile(name, level)
except ValueError as e:
    if 'Profile not found' in str(e):
        name = pick_from(profiler.list_profiles())  # correct the name interactively
        result = profiler.shrink_profile(name, level)
    else:
        raise

Prevention

When it happens

Trigger: shrink_profile('my-profile') before the profile was ever created; typos in the profile name; profiles_dir customized so the name resolves elsewhere; passing a file path (e.g. the .zip export) instead of the directory.

Common situations: Automated cleanup scripts running before first profile creation; renaming profiles; moving profiles_dir via config after profiles were made.

Related errors


AI-assisted analysis of unclecode/crawl4ai@7e80152142 (2026-08-14). Data as JSON: /api/errors/340ab471dcebdef6. Report an issue: GitHub.