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 ⇒ Object
- #dispose_prompt(reason) ⇒ Object
-
#handle(accept: nil, user_text: nil) ⇒ Async::Task[Hash[String, untyped]]
Handle the user prompt.
- #handle_prompt_closed(params) ⇒ Object
-
#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 inherited from EventEmitter
#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 ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/puppeteer/bidi/core/user_prompt.rb', line 67 def dispose return if @disposed @reason ||= "User prompt already closed, probably because the associated browsing context was destroyed." emit(:closed, @reason) super end |
#dispose_prompt(reason) ⇒ Object
110 111 112 113 |
# File 'lib/puppeteer/bidi/core/user_prompt.rb', line 110 def dispose_prompt(reason) @reason = reason dispose end |
#handle(accept: nil, user_text: nil) ⇒ Async::Task[Hash[String, untyped]]
Handle the user prompt
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/puppeteer/bidi/core/user_prompt.rb', line 52 def handle(accept: nil, user_text: nil) Async do raise UserPromptClosedError, @reason if closed? params = { context: @info["context"] } params[:accept] = accept unless accept.nil? params[:userText] = user_text if user_text session.async_send_command("browsingContext.handleUserPrompt", params).wait # The handled event is emitted before the command response resolves. @result end end |
#handle_prompt_closed(params) ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/puppeteer/bidi/core/user_prompt.rb', line 102 def handle_prompt_closed(params) return unless params["context"] == @browsing_context.id @result = params emit(:handled, params) dispose_prompt("User prompt already handled.") 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
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/puppeteer/bidi/core/user_prompt.rb', line 90 def initialize_prompt # Listen for browsing context closure @context_closed_listener = proc do |reason| dispose_prompt("User prompt already closed: #{reason}") end @browsing_context.on(:closed, &@context_closed_listener) # Listen for prompt closed event @prompt_closed_listener = method(:handle_prompt_closed).to_proc session.on("browsingContext.userPromptClosed", &@prompt_closed_listener) end |
#perform_dispose ⇒ Object
77 78 79 80 81 82 |
# File 'lib/puppeteer/bidi/core/user_prompt.rb', line 77 def perform_dispose @browsing_context.off(:closed, &@context_closed_listener) if @context_closed_listener session.off("browsingContext.userPromptClosed", &@prompt_closed_listener) if @prompt_closed_listener @disposables.dispose remove_all_listeners end |
#session ⇒ Object
86 87 88 |
# File 'lib/puppeteer/bidi/core/user_prompt.rb', line 86 def session @browsing_context.user_context.browser.session end |