D4Vinci/Scrapling · error · ValueError
Init script is not a file: {value}
Error message
Init script is not a file: {value} What it means
Raised when init_script points to an existing path but it is not a regular file (Path.is_file() is False) — typically a directory or a special file. Scrapling needs a readable JS file to inject, so directories/symlinks-to-dirs are rejected.
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 = FalseView on GitHub (pinned to 5d213a2d47)
Solutions
- Pass the path to the actual .js file, not its containing directory
- Concatenate scripts yourself if you have several, then pass one file
Example fix
// before session = StealthySession(init_script='/app/inject_scripts') # a directory // after session = StealthySession(init_script='/app/inject_scripts/stealth.js')
Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path assert Path(init_script).is_file(), 'init_script must be a file, not a directory'
Type guard
def is_script_file(p: str) -> bool:
path = Path(p)
return path.is_file() and path.suffix == '.js' Prevention
- Pass the .js file path itself, never its parent directory
- If you have multiple scripts, concatenate them into one file before passing
When it happens
Trigger: Passing a directory path (e.g. the folder containing several scripts) as init_script, or a device/socket path.
Common situations: Assuming init_script accepts a directory of scripts; globbing that returns a directory; pointing at /dev/... special files.
Related errors
- Init script path not found: {value}
- Init script is not an absolute path: {value}
- Browser executable path not found: {value}
- Browser executable is not a file: {value}
- Browser executable is not an absolute path: {value}
AI-assisted analysis of D4Vinci/Scrapling@5d213a2d47 (2026-08-14).
Data as JSON: /api/errors/01488bc9f2f26902.
Report an issue: GitHub.