Class: Puppeteer::Bidi::Dialog

Inherits:
Object
  • Object
show all
Defined in:
lib/puppeteer/bidi/dialog.rb,
sig/puppeteer/bidi/dialog.rbs

Overview

Dialog instances are dispatched by Page via the :dialog event.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prompt) ⇒ Dialog

Returns a new instance of Dialog.

RBS:

  • prompt: Core::UserPrompt -- Core user prompt

  • return: void

Parameters:



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/puppeteer/bidi/dialog.rb', line 20

def initialize(prompt)
  @prompt = prompt
  @type = prompt.info["type"]
  @message = prompt.info["message"]
  @default_value = prompt.info.fetch("defaultValue", "")
  @handled = prompt.handled?

  prompt.once(:handled) do
    @handled = true
  end
end

Instance Attribute Details

#default_valueString (readonly)

Signature:

  • String

Returns:

  • (String)


10
11
12
# File 'lib/puppeteer/bidi/dialog.rb', line 10

def default_value
  @default_value
end

#messageString (readonly)

Signature:

  • String

Returns:

  • (String)


9
10
11
# File 'lib/puppeteer/bidi/dialog.rb', line 9

def message
  @message
end

#typeString (readonly)

Signature:

  • String

Returns:

  • (String)


8
9
10
# File 'lib/puppeteer/bidi/dialog.rb', line 8

def type
  @type
end

Class Method Details

.from(prompt) ⇒ Dialog

RBS:

  • prompt: Core::UserPrompt -- Core user prompt

  • return: Dialog -- Public dialog wrapper

Parameters:

Returns:



14
15
16
# File 'lib/puppeteer/bidi/dialog.rb', line 14

def self.from(prompt)
  new(prompt)
end

Instance Method Details

#accept(prompt_text = nil) ⇒ void

This method returns an undefined value.

RBS:

  • prompt_text: String? -- Text entered into a prompt dialog

  • return: void

Parameters:

  • prompt_text (String, nil) (defaults to: nil)


39
40
41
42
43
44
# File 'lib/puppeteer/bidi/dialog.rb', line 39

def accept(prompt_text = nil)
  raise Error, "Cannot accept dialog which is already handled!" if handled?

  @handled = true
  handle(accept: true, text: prompt_text)
end

#dismissvoid

This method returns an undefined value.

RBS:

  • return: void



47
48
49
50
51
52
# File 'lib/puppeteer/bidi/dialog.rb', line 47

def dismiss
  raise Error, "Cannot dismiss dialog which is already handled!" if handled?

  @handled = true
  handle(accept: false)
end

#handle(accept:, text: nil) ⇒ void

This method returns an undefined value.

RBS:

  • accept: bool -- Whether to accept the dialog

  • text: String? -- Prompt text

  • return: void

Parameters:

  • accept: (Boolean)
  • text: (String, nil) (defaults to: nil)


59
60
61
62
# File 'lib/puppeteer/bidi/dialog.rb', line 59

def handle(accept:, text: nil)
  @prompt.handle(accept: accept, user_text: text).wait
  nil
end

#handled?Boolean

RBS:

  • return: bool -- Whether the dialog has been handled

Returns:

  • (Boolean)


33
34
35
# File 'lib/puppeteer/bidi/dialog.rb', line 33

def handled?
  @handled
end