-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[🐛 Bug]: NetworkInterceptor overwrites failed requests with 200 response #13774
Comments
@joebandenburg, thank you for creating this issue. We will troubleshoot it as soon as we can. Info for maintainersTriage this issue by using labels.
If information is missing, add a helpful comment and then
If the issue is a question, add the
If the issue is valid but there is no time to troubleshoot it, consider adding the
If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C),
add the applicable
After troubleshooting the issue, please add the Thank you! |
A workaround, for those that never want to modify the response in their filter, is to always return So instead of: Filter f = next -> req -> {
// Alter the req
return next.execute(req);
} Do this: Filter f = next -> req -> {
// Alter the req
next.execute(req);
return PROCEED_WITH_REQUEST;
} |
Thank you for the details. I am able to reproduce the problem exactly how it is described. Trying to find a solution for the same now. |
… NetworkInterceptor Related to SeleniumHQ#13774
The above PR has an approach where, if it is a known error to ChromeDevTools, then the response contains the error reason, I have added a check for this error reason and if it is present, then we continue the request without any modification, which leads to the normal expected behaviour i.e. throw an error. |
The fix looks like a nice way to solve the bug. Thanks! I think the fix is good to merge as it, but there is a possible extension that I think is worth considering. I can imagine a hypothetical scenario where the user may want to intercept the failing request and generate a successful response (essentially the opposite of what I want to do here). One way to do that without radically changing the API is to throw an exception back up the filter chain and if that exception makes it to the top of the chain then call I'm trying to mock this up in a PR but I'm struggling with Bazel and debugging in IntelliJ. |
… NetworkInterceptor This is an alternative solution to SeleniumHQ#13836. Related to SeleniumHQ#13774
… NetworkInterceptor This is an alternative solution to SeleniumHQ#13836. Related to SeleniumHQ#13774
… NetworkInterceptor This is an alternative solution to SeleniumHQ#13836. Related to SeleniumHQ#13774
I've created a draft PR to demonstrate the idea above. |
… NetworkInterceptor Related to SeleniumHQ#13774
Your idea looks good to me. I will merge the changes from my PR and then merge your PR suggestion (can you open it up for review please). Thank you for your insights and contribution, I think both solutions will address all use-cases. |
… NetworkInterceptor Related to SeleniumHQ#13774
…nterceptor This change introduces a new exception, which is thrown through the user's filter chain when the browser fails to get a response for a request and a NetworkInterceptor is in use. This gives the filter an opportunity to catch the exception and return a custom HTTP response. Related to SeleniumHQ#13774
…nterceptor This change introduces a new exception, which is thrown through the user's filter chain when the browser fails to get a response for a request and a NetworkInterceptor is in use. This gives the filter an opportunity to catch the exception and return a custom HTTP response. Related to SeleniumHQ#13774
This issue has been automatically locked since there has not been any recent activity since it was closed. Please open a new issue for related bugs. |
What happened?
I've been using
NetworkInterceptor
successfully with Chrome to add headers to requests. However, I've run into an edge case whereNetworkInterceptor
does the wrong thing.If the request fails by not returning a response (e.g. there's a timeout or the hostname does not exist), Selenium replaces the response with a empty 200 response and returns that to Chrome. This causes Chrome to load an empty page rather than failing.
As you can see from the logs below, the second
Fetch.requestPaused
message from Chrome contains"responseErrorReason":"NameNotResolved"
. After this Selenium sends an inappropriateFetch.getResponseBody
, which fails. Selenium constructs an empty 200 response and passes that back to the user's filter. Whatever that filter return is then sent via aFetch.fulfillRequest
call. As far as I can tell, there is no way for the user's filter to distinguish one of these fake 200 responses for a real 200 response (other than the fact that the response is otherwise empty).I'm not entirely sure how Selenium should handle this error but sending a
Fetch.continueRequest
seems to make sense and makes the behaviour consistent to how Selenium behaves if theNetworkInterceptor
has not been used. i.e. the web driver will throw aWebDriverException
fromdriver.get
.The faulty logic seems to be in
v123Network#createSeMessages
. It checks to see ifresponseErrorReason
is set but otherwise ignores the value, continuing on to try to fetch the response body. When that fails, it assumes the reason for such a failure is due to a redirect response, at which point an empty 200 response is constructed.How can we reproduce the issue?
Relevant log output
Operating System
macOS Sonoma 14.4.1
Selenium version
Java 4.19.1
What are the browser(s) and version(s) where you see this issue?
Chrome 123.0
What are the browser driver(s) and version(s) where you see this issue?
ChromeDriver 123.0
Are you using Selenium Grid?
4.19.1
The text was updated successfully, but these errors were encountered: