Class: Puppeteer::Bidi::Core::UserPrompt
- Inherits:
-
EventEmitter
- Object
- EventEmitter
- Puppeteer::Bidi::Core::UserPrompt
- Includes:
- Disposable::DisposableMixin
- Defined in:
- lib/puppeteer/bidi/core/user_prompt.rb,
sig/puppeteer/bidi/core/user_prompt.rbs
Overview
UserPrompt represents a user prompt (alert, confirm, prompt)
Instance Attribute Summary collapse
-
#browsing_context ⇒ Object
readonly
Returns the value of attribute browsing_context.
-
#info ⇒ Object
readonly
Returns the value of attribute info.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Class Method Summary collapse
-
.from(browsing_context, info) ⇒ UserPrompt
Create a user prompt instance.
Instance Method Summary collapse
-
#closed? ⇒ Object
(also: #disposed?)
Check if the prompt is closed.
- #dispose_prompt(reason) ⇒ Object
-
#handle(accept: nil, user_text: nil) ⇒ Hash[String, untyped]
Handle the user prompt.
-
#handled? ⇒ Boolean
Check if the prompt has been handled Auto-handled prompts return true immediately.
-
#initialize(browsing_context, info) ⇒ UserPrompt
constructor
A new instance of UserPrompt.
- #initialize_prompt ⇒ Object
- #perform_dispose ⇒ Object
- #session ⇒ Object
Methods included from Disposable::DisposableMixin
Methods inherited from EventEmitter
#dispose, #emit, #off, #on, #once, #remove_all_listeners
Constructor Details
#initialize(browsing_context, info) ⇒ UserPrompt
Returns a new instance of UserPrompt.
23 24 25 26 27 28 29 30 |
# File 'lib/puppeteer/bidi/core/user_prompt.rb', line 23 def initialize(browsing_context, info) super() @browsing_context = browsing_context @info = info @reason = nil @result = nil @disposables = Disposable::DisposableStack.new end |
Instance Attribute Details
#browsing_context ⇒ Object (readonly)
Returns the value of attribute browsing_context.
21 22 23 |
# File 'lib/puppeteer/bidi/core/user_prompt.rb', line 21 def browsing_context @browsing_context end |
#info ⇒ Object (readonly)
Returns the value of attribute info.
21 22 23 |
# File 'lib/puppeteer/bidi/core/user_prompt.rb', line 21 def info @info end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
21 22 23 |
# File 'lib/puppeteer/bidi/core/user_prompt.rb', line 21 def result @result end |
Class Method Details
.from(browsing_context, info) ⇒ UserPrompt
Create a user prompt instance
15 16 17 18 19 |
# File 'lib/puppeteer/bidi/core/user_prompt.rb', line 15 def self.from(browsing_context, info) prompt = new(browsing_context, info) prompt.send(:initialize_prompt) prompt end |
Instance Method Details
#closed? ⇒ Object Also known as: disposed?
Check if the prompt is closed
33 34 35 |
# File 'lib/puppeteer/bidi/core/user_prompt.rb', line 33 def closed? !@reason.nil? end |
#dispose_prompt(reason) ⇒ Object
96 97 98 99 |
# File 'lib/puppeteer/bidi/core/user_prompt.rb', line 96 def dispose_prompt(reason) @reason = reason dispose end |
#handle(accept: nil, user_text: nil) ⇒ Hash[String, untyped]
Handle the user prompt
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/puppeteer/bidi/core/user_prompt.rb', line 52 def handle(accept: nil, user_text: nil) raise UserPromptClosedError, @reason if closed? params = { context: @info['context'] } params[:accept] = accept unless accept.nil? params[:userText] = user_text if user_text session.send_command('browsingContext.handleUserPrompt', params) # The result is set by the userPromptClosed event before this returns @result end |
#handled? ⇒ Boolean
Check if the prompt has been handled Auto-handled prompts return true immediately
42 43 44 45 46 |
# File 'lib/puppeteer/bidi/core/user_prompt.rb', line 42 def handled? handler = @info['handler'] return true if handler == 'accept' || handler == 'dismiss' !@result.nil? end |
#initialize_prompt ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/puppeteer/bidi/core/user_prompt.rb', line 80 def initialize_prompt # Listen for browsing context closure @browsing_context.once(:closed) do |reason| dispose_prompt("User prompt already closed: #{reason}") end # Listen for prompt closed event session.on('browsingContext.userPromptClosed') do |params| next unless params['context'] == @browsing_context.id @result = params emit(:handled, params) dispose_prompt('User prompt handled') end end |
#perform_dispose ⇒ Object
67 68 69 70 71 72 |
# File 'lib/puppeteer/bidi/core/user_prompt.rb', line 67 def perform_dispose @reason ||= 'User prompt already closed, probably because the associated browsing context was destroyed.' emit(:closed, @reason) @disposables.dispose super end |
#session ⇒ Object
76 77 78 |
# File 'lib/puppeteer/bidi/core/user_prompt.rb', line 76 def session @browsing_context.user_context.browser.session end |