rubycdp / ferrum

Headless Chrome Ruby API
https://ferrum.rubycdp.com
MIT License
1.69k stars 120 forks source link

Chrome error: "Unable to create temporary file" on Windows with JRuby #402

Open jemelyah opened 10 months ago

jemelyah commented 10 months ago

OS: Microsoft Windows Server 2019 Datacenter JRuby version: 9.3.7.0 Ferrum version: 0.13 Chrome version: 116.0.5845.187

When running data stream operations on Windows/JRuby, Chrome fails with "Unable to create temporary file".

irb(main):002:0> browser = Ferrum::Browser.new
=> #<Ferrum::Browser:0x6f65a203 @process=#<Ferrum::Browser::Process:0xd180961 @process_timeout=10, @xvfb=nil, @default_user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/116.0.5845.187 Safari/537.36", @protocol_version="1.3", @ws_url=#<Addressable::URI:0xfa4 URI:ws://127.0.0.1:58348/devtools/browser/39d8d06c-853a-4a85-b526-0975c8967663>, @browser_version="HeadlessChrome/116.0.5845.187", @user_data_dir="C:/jruby-9.3.7.0/tmp/ferrum_user_data_dir_", @env={}, @pid=4668, @logger=nil, @process=#<Java::JavaLang::ProcessImpl:0x4af7ac25>, @v8_version="11.6.189.20", @webkit_version="537.36 (@b2eab7500a18bd4d372f10149c6223fdfe48e3be)", @command=#<Ferrum::Browser::Command:0x3cf06a01 @defaults=#<Ferrum::Browser::Options::Chrome:0x71ee2fff>, @flags={"headless"=>nil, "disable-gpu"=>nil, "hide-scrollbars"=>nil, "mute-audio"=>nil, "enable-automation"=>nil, "disable-web-security"=>nil, "disable-session-crashed-bubble"=>nil, "disable-breakpad"=>nil, "disable-sync"=>nil, "no-first-run"=>nil, "use-mock-keychain"=>nil, "keep-alive-for-test"=>nil, "disable-popup-blocking"=>nil, "disable-extensions"=>nil, "disable-hang-monitor"=>nil, "disable-features"=>"site-per-process,TranslateUI", "disable-translate"=>nil, "disable-background-networking"=>nil, "enable-features"=>"NetworkService,NetworkServiceInProcess", "disable-background-timer-throttling"=>nil, "disable-backgrounding-occluded-windows"=>nil, "disable-client-side-phishing-detection"=>nil, "disable-default-apps"=>nil, "disable-dev-shm-usage"=>nil, "disable-ipc-flooding-protection"=>nil, "disable-prompt-on-repost"=>nil, "disable-renderer-backgrounding"=>nil, "force-color-profile"=>"srgb", "metrics-recording-only"=>nil, "safebrowsing-disable-auto-update"=>nil, "password-store"=>"basic", "no-startup-window"=>nil, "remote-debugging-port"=>"0", "remote-debugging-address"=>"127.0.0.1", "window-size"=>"1024,768", "user-data-dir"=>"C:/jruby-9.3.7.0/tmp/ferrum_user_data_dir_"}, @user_data_dir="C:/jruby-9.3.7.0/tmp/ferrum_user_data_dir_", @path="C:/Program Files/Google/Chrome/Application/chrome.exe", @options=#<Ferrum::Browser::Options:0x37fca349 @process_timeout=10, @xvfb=nil, @browser_options={}, @extensions=nil, @ws_max_receive_size=nil, @browser_path=nil, @options={:window_size=>[1024, 768]}, @slowmo=0.0, @save_path=nil, @env=nil, @logger=nil, @pending_connection_errors=true, @browser_name=nil, @window_size=[1024, 768], @timeout=5, @proxy=nil, @port="0", @headless=true, @ignore_default_browser_options=nil, @host="127.0.0.1", @js_errors=false>>, @port=58348, @host="127.0.0.1">, @window_size=[1024, 768], @client=#<Ferrum::Browser::Client:0x77998ea7 @subscriber=#<Ferrum::Browser::Subscriber:0x252d8df6 @__await_delegator__=#<Concurrent::Async::AwaitDelegator:0x36638b59 @delegate=#<Concurrent::Async::AsyncDelegator:0x2f8f40cc @executor=#<Concurrent::CachedThreadPool:0x14d81f2c @synchronous=false, @name="io", @executor=#<Java::JavaUtilConcurrent::ThreadPoolExecutor:0x5dd3727c>, @auto_terminate=true, @max_queue=0, @fallback_policy=:abort>, @delegate=#<Ferrum::Browser::Subscriber:0x252d8df6 ...>, @queue=[], @ruby_pid=7576>>, @__async_delegator__=#<Concurrent::Async::AsyncDelegator:0x2f8f40cc @executor=#<Concurrent::CachedThreadPool:0x14d81f2c @synchronous=false, @name="io", @executor=#<Java::JavaUtilConcurrent::ThreadPoolExecutor:0x5dd3727c>, @auto_terminate=true, @max_queue=0, @fallback_policy=:abort>, @delegate=#<Ferrum::Browser::Subscriber:0x252d8df6 ...>, @queue=[], @ruby_pid=7576>, @__async_initialized__=true, @on={"Target.targetCreated"=>[#<Proc:0x30ef32eb@C:/jruby-9.3.7.0/lib/ruby/gems/shared/gems/ferrum-0.13/lib/ferrum/contexts.rb:54>], "Target.targetInfoChanged"=>[#<Proc:0xbb5f9d@C:/jruby-9.3.7.0/lib/ruby/gems/shared/gems/ferrum-0.13/lib/ferrum/contexts.rb:62>], "Target.targetDestroyed"=>[#<Proc:0x702cfbde@C:/jruby-9.3.7.0/lib/ruby/gems/shared/gems/ferrum-0.13/lib/ferrum/contexts.rb:70>], "Target.targetCrashed"=>[#<Proc:0x5dce5c03@C:/jruby-9.3.7.0/lib/ruby/gems/shared/gems/ferrum-0.13/lib/ferrum/contexts.rb:75>]}>, @pendings={}, @interrupter=#<Ferrum::Browser::Subscriber:0xb76b7d8 @__await_delegator__=#<Concurrent::Async::AwaitDelegator:0x1c135f63 @delegate=#<Concurrent::Async::AsyncDelegator:0x63c4d16 @executor=#<Concurrent::CachedThreadPool:0x14d81f2c @synchronous=false, @name="io", @executor=#<Java::JavaUtilConcurrent::ThreadPoolExecutor:0x5dd3727c>, @auto_terminate=true, @max_queue=0, @fallback_policy=:abort>, @delegate=#<Ferrum::Browser::Subscriber:0xb76b7d8 ...>, @queue=[], @ruby_pid=7576>>, @__async_delegator__=#<Concurrent::Async::AsyncDelegator:0x63c4d16 @executor=#<Concurrent::CachedThreadPool:0x14d81f2c @synchronous=false, @name="io", @executor=#<Java::JavaUtilConcurrent::ThreadPoolExecutor:0x5dd3727c>, @auto_terminate=true, @max_queue=0, @fallback_policy=:abort>, @delegate=#<Ferrum::Browser::Subscriber:0xb76b7d8 ...>, @queue=[], @ruby_pid=7576>, @__async_initialized__=true, @on={}>, @connectable=#<Ferrum::Browser:0x6f65a203 ...>, @thread=#<Thread:0x29bd2796@C:/jruby-9.3.7.0/lib/ruby/gems/shared/gems/ferrum-0.13/lib/ferrum/browser/client.rb:18 sleep>, @command_id=1, @ws=#<Ferrum::Browser::WebSocket:0x174b8d0e @url=#<Addressable::URI:0xfa4 URI:ws://127.0.0.1:58348/devtools/browser/39d8d06c-853a-4a85-b526-0975c8967663>, @driver=#<WebSocket::Driver::Client:0x112530c3 @key="bQQJXXXcxhEdAlYdIH2ifA==", @ready_state=1, @ping_callbacks={}, @socket=#<Ferrum::Browser::WebSocket:0x174b8d0e ...>, @frame=nil, @require_masking=nil, @extensions=#<WebSocket::Extensions:0x75959b0c @index={}, @by_name={}, @rsv3=nil, @in_order=[], @sessions=[], @rsv2=nil, @rsv1=nil>, @listeners={"open"=>[#<Proc:0x4627dfda@C:/jruby-9.3.7.0/lib/ruby/gems/shared/gems/ferrum-0.13/lib/ferrum/browser/web_socket.rb:49 (lambda)>], "message"=>[#<Proc:0xeebc0db@C:/jruby-9.3.7.0/lib/ruby/gems/shared/gems/ferrum-0.13/lib/ferrum/browser/web_socket.rb:54 (lambda)>], "close"=>[#<Proc:0x6ab50d1c@C:/jruby-9.3.7.0/lib/ruby/gems/shared/gems/ferrum-0.13/lib/ferrum/browser/web_socket.rb:67 (lambda)>]}, @masking=true, @max_length=67108863, @pathname="/devtools/browser/39d8d06c-853a-4a85-b526-0975c8967663", @status=101, @options={:max_length=>67108863, :masking=>true}, @message=nil, @headers={"upgrade"=>"WebSocket", "connection"=>"Upgrade", "sec-websocket-accept"=>"R+VRXFCG559ZW1A/+hB1un7tGvc="}, @queue=[], @reader=#<WebSocket::Driver::StreamReader:0xadc3344 @offset=22, @buffer="\x81\x14{\"id\":1,\"result\":{}}">, @protocols=[], @http=#<WebSocket::HTTP::Response:0x484302ee @code=101, @buffer=[], @env={"rack.input"=>#<StringIO:0x778197c0>}, @headers={"upgrade"=>"WebSocket", "connection"=>"Upgrade", "sec-websocket-accept"=>"R+VRXFCG559ZW1A/+hB1un7tGvc="}, @stage=2>, @accept="R+VRXFCG559ZW1A/+hB1un7tGvc=", @stage=0>, @thread=#<Thread:0x1c2cdc67@C:/jruby-9.3.7.0/lib/ruby/gems/shared/gems/ferrum-0.13/lib/ferrum/browser/web_socket.rb:30 sleep>, @logger=nil, @messages=#<Thread::Queue:0x4c28f97e>, @screenshot_commands={}, @sock=#<TCPSocket:fd 1792>>>, @timeout=5, @contexts=#<Ferrum::Contexts:0x21d8da75 @browser=#<Ferrum::Browser:0x6f65a203 ...>, @contexts=#<Concurrent::Map:0x5a1c7619 entries=0 default_proc=nil>>, @options=#<Ferrum::Browser::Options:0x37fca349 @process_timeout=10, @xvfb=nil, @browser_options={}, @extensions=nil, @ws_max_receive_size=nil, @browser_path=nil, @options={:window_size=>[1024, 768]}, @slowmo=0.0, @save_path=nil, @env=nil, @logger=nil, @pending_connection_errors=true, @browser_name=nil, @window_size=[1024, 768], @timeout=5, @proxy=nil, @port="0", @headless=true, @ignore_default_browser_options=nil, @host="127.0.0.1", @js_errors=false>>

irb(main):003:0> browser.go_to("https://google.com/")
=> "8D6E80BDDE787DAC03C5E81A20BF681B"
irb(main):004:0> browser.mhtml
Traceback (most recent call last):
       10: from C:/jruby-9.3.7.0/bin/jirb:13:in `<main>'
        9: from org/jruby/RubyKernel.java:1237:in `catch'
        8: from org/jruby/RubyKernel.java:1237:in `catch'
        7: from org/jruby/RubyKernel.java:1507:in `loop'
        6: from org/jruby/RubyKernel.java:1091:in `eval'
        5: from (irb):4:in `evaluate'
        4: from C:/jruby-9.3.7.0/lib/ruby/gems/shared/gems/ferrum-0.13/lib/ferrum/page/screenshot.rb:138:in `mhtml'
        3: from C:/jruby-9.3.7.0/lib/ruby/gems/shared/gems/ferrum-0.13/lib/ferrum/page.rb:276:in `command'
        2: from C:/jruby-9.3.7.0/lib/ruby/gems/shared/gems/ferrum-0.13/lib/ferrum/browser/client.rb:49:in `command'
        1: from C:/jruby-9.3.7.0/lib/ruby/gems/shared/gems/ferrum-0.13/lib/ferrum/browser/client.rb:97:in `raise_browser_error'
Ferrum::BrowserError (Unable to create temporary file)

I needed to implement my own solution to start the browser process in this case, as per https://github.com/rubycdp/ferrum/issues/400.

jemelyah commented 5 months ago

@route I am currently testing the original problem on Windows, this goes away when https://github.com/rubycdp/ferrum/pull/401 is implemented.