evaluateHandle<T extends JsHandle> method
The only difference between Page.evaluate and Page.evaluateHandle is that Page.evaluateHandle returns in-page object (JSHandle).
If the function passed to the Page.evaluateHandle returns a Promise
,
then Page.evaluateHandle would wait for the promise to resolve and
return its value.
A JavaScript expression can also be passed in instead of a function:
// Get an handle for the 'document'
var aHandle = await page.evaluateHandle('document');
JSHandle
instances can be passed as arguments to the Page.evaluateHandle:
var aHandle = await page.evaluateHandle('() => document.body');
var resultHandle = await page.evaluateHandle(
'body => body.innerHTML',
args: [aHandle],
);
print(await resultHandle.jsonValue);
await resultHandle.dispose();
Shortcut for Page.mainFrame.executionContext.evaluateHandle
.
Parameters:
pageFunction
Function to be evaluated in the page contextargs
Arguments to pass topageFunction
returns: Future which resolves to the return value of pageFunction
as
in-page object (JSHandle)
Implementation
Future<T> evaluateHandle<T extends JsHandle>(
@Language('js') String pageFunction, {
List<dynamic>? args,
}) async {
var context = await mainFrame.executionContext;
return context.evaluateHandle(pageFunction, args: args);
}