Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thread.rb: terminated with exception #461

Open
georgils opened this issue May 31, 2024 · 1 comment
Open

thread.rb: terminated with exception #461

georgils opened this issue May 31, 2024 · 1 comment
Assignees

Comments

@georgils
Copy link

georgils commented May 31, 2024

**Describe the bug**
My script crashes after a Ferrum thread throws an exception.
First I get this:
#<Thread:0x0000027cd26b3900 C:/Users/User/.gem/ruby/3.2.0/gems/ferrum-0.15/lib/ferrum/utils/thread.rb:9 run> terminated with exception (report_on_exception is true): C:/Users/User/.gem/ruby/3.2.0/gems/ferrum-0.15/lib/ferrum/network.rb:376:in block in subscribe_request_will_be_sent': undefined method `response=' for nil:NilClass (NoMethodError)

      previous_exchange.response = response
                       ^^^^^^^^^^^
    from C:/Users/User/.gem/ruby/3.2.0/gems/ferrum-0.15/lib/ferrum/client/subscriber.rb:71:in `block in call'
    from C:/Users/User/.gem/ruby/3.2.0/gems/ferrum-0.15/lib/ferrum/client/subscriber.rb:69:in `each'
    from C:/Users/User/.gem/ruby/3.2.0/gems/ferrum-0.15/lib/ferrum/client/subscriber.rb:69:in `each_with_index'
    from C:/Users/User/.gem/ruby/3.2.0/gems/ferrum-0.15/lib/ferrum/client/subscriber.rb:69:in `call'
    from C:/Users/User/.gem/ruby/3.2.0/gems/ferrum-0.15/lib/ferrum/client/subscriber.rb:50:in `block (2 levels) in start'
    from C:/Users/User/.gem/ruby/3.2.0/gems/ferrum-0.15/lib/ferrum/client/subscriber.rb:46:in `loop'
    from C:/Users/User/.gem/ruby/3.2.0/gems/ferrum-0.15/lib/ferrum/client/subscriber.rb:46:in `block in start'
    from C:/Users/User/.gem/ruby/3.2.0/gems/ferrum-0.15/lib/ferrum/utils/thread.rb:13:in `block in spawn'`

followed by

undefined method include?' for nil:NilClass (NoMethodError)

                            if traffic.url.include?(CGI.escape(x))
                                          ^^^^^^^^^

from my code where traffic is from page.network.traffic.each { |traffic| .....}

Obviously my traffic.url is nil but somehow I don't believe this should be possible, I guess Chrome would not even create a request if the url is missing.

To Reproduce
Sorry but can't imagine how to provide a meaningful context... I'll try to describe: 1. sending Chrome to a url. 2. filling a form which triggers a xhr 3. analyzing network traffic to obtain the specific xhr in question by filtering the array of Exchanges page.network.traffic on their url property.

Expected behavior

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser [Version 125.0.6422.77 (Official Build) (64-bit)]
  • Version [v 0.15]
  • Ruby Version Manager [uru v.0.8.5]

Additional context
I don't know if this has something to do with the above (another nil object), but look at what I get in irb:

irb(main):062:0> browser = Ferrum::Browser.new(url: 'https://github.com/rubycdp/ferrum#frames') C:/Users/User/.gem/ruby/3.2.0/gems/ferrum-0.15/lib/ferrum/browser/process.rb:177:in ws_url=': undefined method `host' for nil:NilClass (NoMethodError)

    @host = @ws_url.host
                   ^^^^^
    from C:/Users/User/.gem/ruby/3.2.0/gems/ferrum-0.15/lib/ferrum/browser/process.rb:73:in `initialize'
    from C:/Users/User/.gem/ruby/3.2.0/gems/ferrum-0.15/lib/ferrum/browser.rb:244:in `new'
    from C:/Users/User/.gem/ruby/3.2.0/gems/ferrum-0.15/lib/ferrum/browser.rb:244:in `start'
    from C:/Users/User/.gem/ruby/3.2.0/gems/ferrum-0.15/lib/ferrum/browser.rb:132:in `initialize'
    from (irb):62:in `new'
    from (irb):62:in `<main>'
    from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/irb-1.6.2/exe/irb:11:in `<top (required)>'
    from C:/Ruby32-x64/bin/irb:33:in `load'
    from C:/Ruby32-x64/bin/irb:33:in `<main>'`
@georgils
Copy link
Author

georgils commented Jun 2, 2024

I took a look at the network.rb source code and did some debugging which led me to the conclusion that the problem is me periodically calling page.network.clear(:traffic). I was doing it instinctively as if cleaning traffic in Developer Tools - I believe what DevTools/Network shows is just a log and deleting it won't affect the browser's behaviour. But maybe this is not the case with Ferrum - I seem to be deleting an Exchange object and that's why select(request.id)[-2] returns nil...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants