Class: Puppeteer::WorkerWorld

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

Overview

rbs_inline: enabled

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Object

Parameters:



8
9
10
11
12
13
# File 'lib/puppeteer/web_worker.rb', line 8

def initialize(client)
  @client = client
  @context_promise = Async::Promise.new
  @task_manager = Puppeteer::TaskManager.new
  @disposed = false
end

Instance Attribute Details

#task_managerObject (readonly)

Returns the value of attribute task_manager.

Returns:

  • (Object)


15
16
17
# File 'lib/puppeteer/web_worker.rb', line 15

def task_manager
  @task_manager
end

Instance Method Details

#detached?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/puppeteer/web_worker.rb', line 92

def detached?
  @disposed
end

#disposevoid

This method returns an undefined value.



81
82
83
84
85
86
87
88
89
90
# File 'lib/puppeteer/web_worker.rb', line 81

def dispose
  return if @disposed

  @disposed = true
  error = Puppeteer::WaitTask::TerminatedError.new(
    'waitForFunction failed: worker got detached.',
  )
  @context_promise.reject(error) unless @context_promise.resolved?
  @task_manager.terminate_all(error)
end

#evaluate(page_function, *args) ⇒ Object

Parameters:

  • page_function (String)
  • args (Object)

Returns:

  • (Object)


36
37
38
# File 'lib/puppeteer/web_worker.rb', line 36

def evaluate(page_function, *args)
  execution_context.evaluate(page_function, *args)
end

#evaluate_handle(page_function, *args) ⇒ Puppeteer::JSHandle

Parameters:

  • page_function (String)
  • args (Object)

Returns:



45
46
47
# File 'lib/puppeteer/web_worker.rb', line 45

def evaluate_handle(page_function, *args)
  execution_context.evaluate_handle(page_function, *args)
end

#execution_contextPuppeteer::ExecutionContext



24
25
26
27
28
29
30
31
# File 'lib/puppeteer/web_worker.rb', line 24

def execution_context
  if @disposed
    raise Puppeteer::WaitTask::TerminatedError.new(
      'waitForFunction failed: worker got detached.',
    )
  end
  @context_promise.wait
end

#framenil

Returns:

  • (nil)


76
77
78
# File 'lib/puppeteer/web_worker.rb', line 76

def frame
  nil
end

#set_context(context) ⇒ void

This method returns an undefined value.

Parameters:



19
20
21
# File 'lib/puppeteer/web_worker.rb', line 19

def set_context(context)
  @context_promise.resolve(context) unless @context_promise.resolved?
end

#wait_for_function(page_function, args: [], polling: nil, timeout: nil) ⇒ Puppeteer::JSHandle

Parameters:

  • page_function (String)
  • args: (Array[untyped]) (defaults to: [])
  • polling: (Integer, String, nil) (defaults to: nil)
  • timeout: (Integer, nil) (defaults to: nil)

Returns:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/puppeteer/web_worker.rb', line 56

def wait_for_function(page_function, args: [], polling: nil, timeout: nil)
  runner = lambda do
    wait_task = Puppeteer::WaitTask.new(
      dom_world: self,
      predicate_body: page_function,
      title: 'function',
      polling: polling || 100,
      timeout: timeout.nil? ? 30_000 : timeout,
      args: args,
    )
    wait_task.await_promise
  end
  return runner.call if Async::Task.current?

  Sync { runner.call }
end