Class: Playwright::ConsoleMessage

Inherits:
PlaywrightApi show all
Defined in:
lib/playwright_api/console_message.rb,
sig/playwright.rbs

Overview

ConsoleMessage objects are dispatched by page via the [event: Page.console] event. For each console message logged in the page there will be corresponding event in the Playwright context.

# Listen for all console logs
page.on("console", lambda msg: print(msg.text))

# Listen for all console events and handle errors
page.on("console", lambda msg: print(f"error: {msg.text}") if msg.type == "error" else None)

# Get the next console log
with page.expect_console_message() as msg_info:
    # Issue console.log inside the page
    page.evaluate("console.log('hello', 42, { foo: 'bar' })")
msg = msg_info.value

# Deconstruct print arguments
msg.args[0].json_value() # hello
msg.args[1].json_value() # 42

Instance Method Summary collapse

Methods inherited from PlaywrightApi

#initialize, unwrap, wrap

Constructor Details

This class inherits a constructor from Playwright::PlaywrightApi

Instance Method Details

#argsArray[untyped]

List of arguments passed to a console function call. See also [event: Page.console].

Returns:

  • (Array[untyped])


28
29
30
# File 'lib/playwright_api/console_message.rb', line 28

def args
  wrap_impl(@impl.args)
end

#locationHash[untyped, untyped]

Returns:

  • (Hash[untyped, untyped])


32
33
34
# File 'lib/playwright_api/console_message.rb', line 32

def location
  wrap_impl(@impl.location)
end

#pagenil, Page

The page that produced this console message, if any.

Returns:



38
39
40
# File 'lib/playwright_api/console_message.rb', line 38

def page
  wrap_impl(@impl.page)
end

#textString

The text of the console message.

Returns:

  • (String)


44
45
46
# File 'lib/playwright_api/console_message.rb', line 44

def text
  wrap_impl(@impl.text)
end

#timestampFloat

The timestamp of the console message in milliseconds since the Unix epoch.

Returns:

  • (Float)


50
51
52
# File 'lib/playwright_api/console_message.rb', line 50

def timestamp
  wrap_impl(@impl.timestamp)
end

#type"log", ...

Returns:

  • ("log", "debug", "info", "error", "warning", "dir", "dirxml", "table", "trace", "clear", "startGroup", "startGroupCollapsed", "endGroup", "assert", "profile", "profileEnd", "count", "time", "timeEnd")


54
55
56
# File 'lib/playwright_api/console_message.rb', line 54

def type
  wrap_impl(@impl.type)
end

#workernil, Worker

The web worker or service worker that produced this console message, if any. Note that console messages from web workers also have non-null [method: ConsoleMessage.page].

Returns:



60
61
62
# File 'lib/playwright_api/console_message.rb', line 60

def worker
  wrap_impl(@impl.worker)
end