Skip to main content

init_script_from_js

Function init_script_from_js 

Source
pub fn init_script_from_js<'js>(
    ctx: &Ctx<'js>,
    script: Value<'js>,
    arg: Option<Value<'js>>,
) -> Result<(InitScriptSource, Option<Value>)>
Expand description

Lower an addInitScript-style JS argument into ferridriver::options::InitScriptSource plus an optional JSON arg. Mirrors Playwright’s Function | string | { path?: string, content?: string } union from /tmp/playwright/packages/playwright-core/src/client/page.ts:520 — all semantic lowering (function body via .toString(), path/content precedence, null-vs-undefined preservation for arg) happens here synchronously so the async binding method can immediately hand owned, Send-safe values to Rust core.

Returns an error for non-matching script shapes or for a missing { path, content } entry. The (source|path|content) + arg rejection is left to ferridriver::options::evaluation_script so both binding layers share the exact error text Playwright ships.