It will run to the end, although an error will occur.
Comment out browser.disconnect and the error disappears
Is it because the part doing parallel processing is not terminating at the time of disconnect?
connect do |browser|
xxx
end
Is same.
class Scraping
def execute
browser = Puppeteer.connect(
browser_ws_endpoint: "ws://docker.for.mac.localhost:9222/devtools/browser/xxxx",
// Error also occurs in the following
// browser_ws_endpoint: "ws://127.0.0.1:9222/devtools/browser/xxx"
)
browser.disconnect
p 1111
end
end
bundle exec rails c
Scraping.new.execute
W, [2024-05-05T13:27:41.016862 #201] WARN -- : Protocol error (Target.setAutoAttach): Session closed. Most likely the iframe has been closed. (Puppeteer::CDPSession::Error)
/usr/local/bundle/gems/puppeteer-ruby-0.45.4/lib/puppeteer/cdp_session.rb:37:in `async_send_message'
/usr/local/bundle/gems/puppeteer-ruby-0.45.4/lib/puppeteer/chrome_target_manager.rb:244:in `block in handle_attached_to_target'
/usr/local/bundle/gems/puppeteer-ruby-0.45.4/lib/puppeteer/concurrent_ruby_utils.rb:62:in `block in future'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/promises.rb:1593:in `evaluate_to'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/promises.rb:1776:in `block in on_resolvable'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:359:in `run_task'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:350:in `block (3 levels) in create_worker'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:341:in `loop'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:341:in `block (2 levels) in create_worker'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:340:in `catch'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:340:in `block in create_worker'
W, [2024-05-05T13:27:41.023681 #201] WARN -- : 2 errors
Protocol error (Target.setAutoAttach): Target Closed. (Puppeteer::Connection::ProtocolError)
Protocol error (Runtime.runIfWaitingForDebugger): Target Closed. (Puppeteer::Connection::ProtocolError) (Concurrent::MultipleErrors)
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/promises.rb:1268:in `raise'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/promises.rb:1268:in `wait_until_resolved!'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/promises.rb:998:in `value!'
/usr/local/bundle/gems/puppeteer-ruby-0.45.4/lib/puppeteer/concurrent_ruby_utils.rb:32:in `await_all'
/usr/local/bundle/gems/puppeteer-ruby-0.45.4/lib/puppeteer/chrome_target_manager.rb:243:in `block in handle_attached_to_target'
/usr/local/bundle/gems/puppeteer-ruby-0.45.4/lib/puppeteer/concurrent_ruby_utils.rb:62:in `block in future'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/promises.rb:1593:in `evaluate_to'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/promises.rb:1776:in `block in on_resolvable'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:359:in `run_task'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:350:in `block (3 levels) in create_worker'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:341:in `loop'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:341:in `block (2 levels) in create_worker'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:340:in `catch'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:340:in `block in create_worker'
W, [2024-05-05T13:27:41.024516 #201] WARN -- : 2 errors
Protocol error (Target.setAutoAttach): Target Closed. (Puppeteer::Connection::ProtocolError)
Protocol error (Runtime.runIfWaitingForDebugger): Target Closed. (Puppeteer::Connection::ProtocolError) (Concurrent::MultipleErrors)
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/promises.rb:1268:in `raise'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/promises.rb:1268:in `wait_until_resolved!'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/promises.rb:998:in `value!'
/usr/local/bundle/gems/puppeteer-ruby-0.45.4/lib/puppeteer/concurrent_ruby_utils.rb:32:in `await_all'
/usr/local/bundle/gems/puppeteer-ruby-0.45.4/lib/puppeteer/chrome_target_manager.rb:243:in `block in handle_attached_to_target'
/usr/local/bundle/gems/puppeteer-ruby-0.45.4/lib/puppeteer/concurrent_ruby_utils.rb:62:in `block in future'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/promises.rb:1593:in `evaluate_to'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/promises.rb:1776:in `block in on_resolvable'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:359:in `run_task'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:350:in `block (3 levels) in create_worker'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:341:in `loop'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:341:in `block (2 levels) in create_worker'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:340:in `catch'
/usr/local/bundle/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:340:in `block in create_worker'
1111
Step To Reproduce / Observed behavior
It will run to the end, although an error will occur. Comment out browser.disconnect and the error disappears Is it because the part doing parallel processing is not terminating at the time of disconnect?
connect do |browser| xxx end Is same.
bundle exec rails c Scraping.new.execute
Expected behavior
No error
Environment
puppeteer-ruby (0.45.4) concurrent-ruby (>= 1.1, < 1.3) mime-types (>= 3.0) websocket-driver (>= 0.6.0)
Paste the output of
ruby --version
3.1.2p20Mac
Connect to host's chrome from docker container
host