温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/bun/WebView/evaluate
点击访问原文链接

WebView.evaluate method | Bun module | Bun

WebView.evaluate method | Bun module | BunBuildDocsReferenceGuidesBlogDiscord/Bun/WebView/evaluateMevaluate

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/Bun/WebView/evaluateMevaluate

method

WebView.evaluate r.json())"); // awaited ``` **`script` must be an expression.** For statement sequences, wrap in an IIFE: `evaluate("(() => { let x = f(); return x + 1 })()")`. Values that `JSON.stringify` collapses to `undefined` (functions, symbols, `undefined` itself) resolve to `undefined`. Circular references reject. Only one `evaluate()` may be in flight at a time per view; a second concurrent call throws `ERR_INVALID_STATE`." data-algolia-static="false" data-algolia-merged="false" data-type="Method">evaluateT = unknown>(script: string): PromiseT>;

Run a JavaScript expression in the page's main frame and return the result as a native JS value.

The expression is wrapped as await (${script}) — if it evaluates to a Promise, the promise is awaited. The resolved value is serialized page-side via JSON.stringify and deserialized here, so arrays and objects come back as real structures:

await view.evaluate("document.title"); // string
await view.evaluate("[1, 2, 3]"); // number[]
await view.evaluate("({ a: 1, b: true })"); // { a: number, b: boolean }
await view.evaluate("fetch('/api').then(r => r.json())"); // awaited

script must be an expression. For statement sequences, wrap in an IIFE: evaluate("(() => { let x = f(); return x + 1 })()").

Values that JSON.stringify collapses to undefined (functions, symbols, undefined itself) resolve to undefined. Circular references reject.

Only one evaluate() may be in flight at a time per view; a second concurrent call throws ERR_INVALID_STATE.

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked with ❤️ in San Francisco

We're hiring →

WebView.evaluate method | Bun module | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    API documentation for method bun.WebView.evaluate | Bun