View Source Playwright.JSHandle (playwright v1.49.1-alpha.1)

Playwright.JSHandle represents an in-page JavaScript object. JSHandles can be created with Playwright.Page.evaluate_handle/3.

Example

handle = Page.evaluate_handle(page, "() => window")

JSHandle prevents the referenced JavaScript object from being garbage collected unless the handle is disposed with Playwright.JSHandle.dispose/1. JSHandles are auto-disposed when their origin frame gets navigated or the parent context gets destroyed.

JSHandle instances can be used as arguments to:

Summary

Types

t()

%Playwright.JSHandle{}

Functions

Returns either nil or the object handle itself, if the object handle is an instance of Playwright.ElementHandle.

Returns the return value from executing param: expression in the browser as a Playwright.JSHandle.

Optional callback implementation for Playwright.SDK.ChannelOwner.init/2.

Types

@type t() :: %Playwright.JSHandle{
  guid: term(),
  initializer: term(),
  listeners: term(),
  parent: term(),
  preview: term(),
  session: term(),
  type: term()
}

%Playwright.JSHandle{}

Functions

@spec as_element(struct()) :: Playwright.ElementHandle.t() | nil

Returns either nil or the object handle itself, if the object handle is an instance of Playwright.ElementHandle.

Link to this function

evaluate(handle, expression, arg \\ nil)

View Source
Link to this function

evaluate_handle(handle, expression, arg \\ nil)

View Source
@spec evaluate_handle(t() | Playwright.ElementHandle.t(), binary(), any()) ::
  Playwright.ElementHandle.t()

Returns the return value from executing param: expression in the browser as a Playwright.JSHandle.

This function passes the handle as the first argument to param: expression.

The only difference between Playwright.JSHandle.evaluate/3 and Playwright.JSHandle.evaluate_handle/3 is that evaluate_handle returns Playwright.JSHandle.

If the expression passed to Playwright.JSHandle.evaluate_handle/3 returns a Promise, Playwright.JSHandle.evaluate_handle/3 waits for the promise to resolve and return its value.

See Playwright.Page.evaluate_handle/3 for more details.

Returns

  • Playwright.ElementHandle.t()

Arguments

key/nametypedescription
expressionparambinary()Function to be evaluated in the page context.
argparamany()Argument to pass to expression (optional)
Link to this function

init(owner, initializer)

View Source
@spec init(
  struct(),
  map()
) :: {atom(), struct()}

Optional callback implementation for Playwright.SDK.ChannelOwner.init/2.

If implemented, the callback will receive:

  1. The newly created "channel owner" struct.
  2. The :initializer received from the Playwright browser server.

The implementation has the option of "patching" the struct as stored in the catalog, and/or binding event handlers.

Example

def init(%{session: session} = owner, _initializer) do
  Channel.bind(session, {:guid, owner.guid}, :close, fn event ->
    Logger.warning("Closing #{inspect(event.target)}")
  end)

  {:ok, %{owner | version: "1.2.3"}}
end

Returns

  • {:ok, struct()}

Arguments

key/nametypedescription
ownerparamstruct()The newly created channel owner (resource).
initializerparamstruct()The initializer received from with the channel owner instance was derived.