-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[rb] Add Bidi Network Response Handler #14900
base: trunk
Are you sure you want to change the base?
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
@@ -56,7 +58,9 @@ module WebDriver | |||
it 'adds a request handler' do | |||
reset_driver!(web_socket_url: true) do |driver| | |||
network = described_class.new(driver) | |||
network.add_request_handler | |||
network.add_request_handler { |event| network.continue_with_request(request_id: network.fetch_id(event)) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I roughly recall our conversation about high-level BiDi API, but I think the idea was about something similar to the following:
# filter is essentially a list of URL patterns that should be intercepted
network.add_request_handler(filter) do |request|
# ... here you can mutate the request as you wish
request.headers['My-Custom-Header'] = 'Value'
request.continue # this would continue the original (or mutated) request
# or
request.fail # this would fail the request
end
@diemol @pujagani @titusfortner Am I recalling this correctly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw the filter implementation on the Java bindings, so I can try to translate that to Ruby now and see if that aligns with the idea from the conversations
Is there any docs or PR that I can read? maybe I skipped the one talking about filters :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there is any implementation yet, but a filter in Java would probably be a good start. Maybe too much for Ruby and we can just use regexp instead, I suggest you keep it simple and straightforward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@p0deje @pujagani This PR has expanded quite a bit, with a lot of cool additions and modifications from your suggestions but I'm still in doubt about the filtering, only continueWithRequest takes a Url and the user will use the handler as follows now:
network.add_request_handler do |request|
request.method = 'GET'
request.url = url_for('formPage.html')
request.add_header('foo', 'bar')
request.add_header('baz', 'qux')
request.add_cookie('foo', 'bar')
request.body = ({test: 'example'})
request.continue
end
So I'm in doubt about what the filtering will add for the user since the user can use request.url, unless I'm understanding the specification wrong
Specification:
https://w3c.github.io/webdriver-bidi/#command-network-continueRequest
Thanks for the help, and if we decide to implement the filtering I can quickly do it and then fix any other review comments and add the signatures, hopefully we can get this through this weekend or next week!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR has expanded quite a bit, with a lot of cool additions and modifications from your suggestions but I'm still in doubt about the filtering, only continueWithRequest takes a Url and the user will use the handler as follows now
This looks great! One small nitpick from me is why we want extra headers/cookies methods when we can simply mutate headers/cookies
hashes directly?
request.headers['foo'] = 'bar'
request.headers.delete('bar')
request.cookies['foo'] = 'bar'
request.cookies.delete('bar')
So I'm in doubt about what the filtering will add for the user since the user can use request.url, unless I'm understanding the specification wrong
The filtering that is added on https://w3c.github.io/webdriver-bidi/#command-network-addIntercept is useful because it means the client won't be bombarded with ALL requests and instead remote end will be responsible for From user perspective, these two calls would be the same logic:
network.add_request_handler { it.continue if it.url.starts_with?("https://google.com") }
network.add_request_handler(url: "https://google.com") { it.continue }
However, the first variant will require the client to process every single request and if the remote end is run in the cloud (e.g. Sauce Labs), it means a lot of traffic going back and forth between the client and the remote. The second variant doesn't have this issue.
User description
Description
This PR adds support to handle network responses and intercept them
It also refactors the previous implementations for network auth in ruby and allows to pass any method the user wants to the network methods
Now it's possible to call network.add_response_handler
It's also possible to call add_request_handler as follows:
And add auth handler should be called as:
Here is a video of all the test passing, now there are 16 tests from the previous 9 on the original PR:
tests.passing.mov
Formatting results locally on latest PR:
Motivation and Context
To complete the specification stated on #13993 and to get closer to have a full BiDi implementation for the Ruby bindings that the user can use for all their Network related needs
Types of changes
Checklist
PR Type
Enhancement
Description
continue_with_response
methodcontinue_without_auth
andcancel_auth
Changes walkthrough 📝
network.rb
Enhanced network response handling and auth methods
rb/lib/selenium/webdriver/bidi/network.rb
continue_without_auth
andcancel_auth
continue_with_response
method for handling network responsescontinue_with_request
command nameon
methodnetwork.rb
Network handler implementation and management improvements
rb/lib/selenium/webdriver/common/network.rb
fetch_id
for request handlingnetwork_spec.rb
Network response and auth handling test coverage
rb/spec/integration/selenium/webdriver/bidi/network_spec.rb
network_spec.rb
Network response handler integration tests
rb/spec/integration/selenium/webdriver/network_spec.rb
network.rbs
Updated type signatures for network methods
rb/sig/lib/selenium/webdriver/bidi/network.rbs
bidi.rbs
Enhanced callback method type signature
rb/sig/lib/selenium/webdriver/bidi.rbs