D4Vinci/Scrapling · error · ValueError

Init script path not found: {value}

Error message

Init script path not found: {value}

What it means

Raised by _is_invalid_file_path when the `init_script` path does not exist on disk (checked via Path(value).exists()). The init script is a JS file scrapling injects into pages, so it must point to a real file before the session starts.

Source

Thrown at scrapling/engines/_browsers/_validators.py:128

            cdp_msg = _is_invalid_cdp_url(self.cdp_url)
            if cdp_msg:
                raise ValueError(cdp_msg)

        if not self.cookies:
            self.cookies = []
        if not self.extra_flags:
            self.extra_flags = []
        if not self.selector_config:
            self.selector_config = {}
        if not self.additional_args:
            self.additional_args = {}
        if not self.capture_xhr:
            self.capture_xhr = None

        if self.init_script is not None:
            validation_msg = _is_invalid_file_path(self.init_script)
            if validation_msg:
                raise ValueError(validation_msg)

        if self.executable_path is not None:
            validation_msg = _is_invalid_file_path(self.executable_path, "Browser executable")
            if validation_msg:
                raise ValueError(validation_msg)

        if self.block_ads:
            from scrapling.engines.toolbelt.ad_domains import AD_DOMAINS

            if self.blocked_domains:
                self.blocked_domains = self.blocked_domains | set(AD_DOMAINS)
            else:
                self.blocked_domains = set(AD_DOMAINS)


class StealthConfig(PlaywrightConfig, kw_only=True, frozen=False, weakref=True):
    allow_webgl: bool = True
    hide_canvas: bool = False

View on GitHub (pinned to 5d213a2d47)

Solutions

  1. Verify the file exists at runtime: Path(init_script).exists() before constructing the session
  2. Use absolute paths derived from __file__ of your project, not hardcoded strings
  3. In Docker/CI, confirm the script is copied into the image

Example fix

// before
session = StealthySession(init_script='scripts/stealth.js')  # cwd-dependent

// after
from pathlib import Path
script = Path(__file__).parent / 'scripts' / 'stealth.js'
assert script.exists()
session = StealthySession(init_script=str(script))
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path
assert Path(init_script).exists(), f'init script missing: {init_script}'

Type guard

def init_script_exists(p: str) -> bool:
    return Path(p).exists()

Try / catch

try:
    session = StealthySession(init_script=p)
except ValueError as e:
    if 'not found' in str(e):
        p = str(Path(__file__).parent / 'stealth.js')
        session = StealthySession(init_script=p)
    else:
        raise

Prevention

When it happens

Trigger: Passing init_script='/path/to/stealth.js' when the file was moved/deleted, when the working directory changed, or when the path contains a typo.

Common situations: Deployments where the script ships in a different location than on the dev machine, Docker containers missing the file, or CI environments.

Related errors


AI-assisted analysis of D4Vinci/Scrapling@5d213a2d47 (2026-08-14). Data as JSON: /api/errors/522b4d0dd50a6587. Report an issue: GitHub.