Skip to content

Conversation

@CodeMeister
Copy link
Contributor

@CodeMeister CodeMeister commented May 15, 2025

UseCase

When I visit /test it downloads main.js which is needed for the page, then pre-loads p1.js, p2.js & p3.js

Frequently there is a PendingConnectionsError on one of the pre-load javascript files.

This feature will allow me to say: Don't raise a PendingConnectionsError for any javascript file, except main.js which is the important one.

Ferrum::Browser.new  base_url: base_url,
                     pending_connection_allowlist: [ %r{*.js} ],
                     pending_connection_blocklist: [ %r{main.js} ] 

Changes

  • README.md: - browser options info updated.

  • lib/ferrum/browser.rb:80 - updated @option comments.

  • lib/ferrum/browser/options.rb:16 - added attr_reader for :pending_connection_allowlist and :pending_connection_blocklist.

  • lib/ferrum/browser/options.rb:34 - set the new options from the arguments.

  • lib/ferrum/page.rb:118 + 539 - added method :process_timeout_error(url) to compare the lists and raise.

  • spec/browser_spec.rb:245 - added tests for both lists.

Cuprite

If this PR is accepted, I'll do a PR for cuprite to include this feature.


Hope you're happy with it: 🤞

…_blocklist added

- Any pending URL that matches the allowlist will not raise a PendingConnectionsError.

- Any pending URL that matches the blocklist will always raise a PendingConnectionsError.
  This takes precedence on the allowlist!

  - README.md updated
@CodeMeister
Copy link
Contributor Author

I'll fix the linting

@CodeMeister
Copy link
Contributor Author

CodeMeister commented May 15, 2025

Linting fixed, but Ruby 3.2 failing on:
rspec ./spec/network/exchange_spec.rb:40 # Ferrum::Network::Exchange#intercepted_request modifies request

My changes have no impact there and all tests pass in the other versions. Can you please re-run the 3.2 tests to see if it's an anomaly?


Triggered tests again with an empty commit - all pass.

🥳

@route
Copy link
Member

route commented May 16, 2025

:pending_connection_errors is only useful for Cuprite and only for local tests that load resources on your local machine. If you use it for a real web chances that you constantly get the error are close to 99% because of the nature of the network.

It should be just turned off by default for Ferrum and on for Cuprite. That was the only idea for this setting.
Making it over-complicated will make things even harder to read and reason about.

@route route closed this May 16, 2025
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

Successfully merging this pull request may close these issues.

2 participants