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.