evaluateHandle<T extends JsHandle> method

Future<T> evaluateHandle<T extends JsHandle>(
  1. @Language.new('js') String pageFunction, {
  2. List? args,
})

The only difference between Frame.evaluate and Frame.evaluateHandle is that Frame.evaluateHandle returns in-page object (JSHandle).

If the function passed to the Frame.evaluateHandle returns a Promise, then Frame.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 frame.evaluateHandle('document');

JSHandle instances can be passed as arguments to the Frame.evaluateHandle:

var aHandle = await frame.evaluateHandle('() => document.body');
var resultHandle = await frame.evaluateHandle(
  'body => body.innerHTML',
  args: [aHandle],
);
print(await resultHandle.jsonValue);
await resultHandle.dispose();

Parameters:

  • pageFunction Function to be evaluated in the page context
  • args Arguments to pass to pageFunction

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,
}) {
  return _mainWorld.evaluateHandle(pageFunction, args: args);
}