You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This PR adds the --enable-chrome-logs argument when starting chromedriver. This allows it to inherit the i/o streams from the browser process. Without this, we have no way to suppress or redirect browser i/o streams, which results in unwanted logging going to the user's console.
🔧 Implementation Notes
I added this to the chrome Service class rather than the chromium Service class because I am not sure if this is also supported by Edge, or is only relevant to Chrome.
💡 Additional Considerations
We should test to make sure this doesn't screw up any other logging features.
🔄 Types of changes
Bug fix (backwards compatible)
PR Type
Bug fix
Description
Add --enable-chrome-logs flag to Chrome service arguments
Enable browser I/O stream inheritance to suppress unwanted console logging
Override command_line_args() method in Chrome service class
Diagram Walkthrough
flowchart LR
A["Chrome Service"] --> B["command_line_args()"]
B --> C["--enable-chrome-logs flag"]
C --> D["Browser I/O streams inherited"]
D --> E["Suppressed console logging"]
Loading
File Walkthrough
Relevant files
Bug fix
service.py
Add Chrome logs flag to service arguments
py/selenium/webdriver/chrome/service.py
Override command_line_args() method to include --enable-chrome-logs flag
Add flag before port and service arguments in command line
Adding '--enable-chrome-logs' unconditionally changes default behavior and may affect users relying on previous ChromeDriver/Chrome logging behavior; verify that this flag exists across supported Chrome/Driver versions and does not regress logging/CI stderr handling.
Ensure that placing '--enable-chrome-logs' before port and appending user-provided service args does not lead to duplicate or conflicting flags (e.g., user also passing '--enable-chrome-logs' or a different '--port'); consider de-duping or precedence rules.
Place the port argument after user-specified service_args to avoid being overridden by a user-provided --port in _service_args. Also, guard against None to prevent a TypeError when no service args are provided.
def command_line_args(self) -> list[str]:
- return ["--enable-chrome-logs", f"--port={self.port}"] + self._service_args+ args = ["--enable-chrome-logs"]+ user_args = self._service_args or []+ # Ensure driver-required port comes last to take precedence+ args.extend(user_args)+ args.append(f"--port={self.port}")+ return args
Apply / Chat
Suggestion importance[1-10]: 9
__
Why: The suggestion correctly identifies a critical issue where a user-provided --port in service_args could override the port managed by the service, leading to connection failures. Moving the port argument to the end ensures its precedence.
Verify that chromedriver versions used in supported environments recognize the --enable-chrome-logs switch; older versions may not accept it and could fail to start or ignore it. Consider feature-detection or graceful fallback if the flag is unrecognized.
Confirm that placing --enable-chrome-logs before --port and ahead of other service args matches chromedriver expectations and does not conflict with flags users pass via service_args (e.g., duplicates or overrides).
Consider allowing users to opt out of --enable-chrome-logs (e.g., via a constructor option) to avoid changing default behavior for consumers who rely on current logging semantics.
Reuse the base implementation to avoid dropping any default/required arguments and to preserve their ordering. Also switch the return annotation to Sequence[str] for broader Python version compatibility. Ensure the chrome logs flag is added only once.
-def command_line_args(self) -> list[str]:- return ["--enable-chrome-logs", f"--port={self.port}"] + self._service_args+def command_line_args(self) -> Sequence[str]:+ base_args = list(super().command_line_args())+ if "--enable-chrome-logs" not in base_args:+ base_args.insert(0, "--enable-chrome-logs")+ return base_args
Apply / Chat
Suggestion importance[1-10]: 7
__
Why: The suggestion correctly points out that overriding command_line_args without calling the parent implementation is brittle. Reusing the base method via super() makes the code more maintainable and robust against future changes in the parent ChromiumService class.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
🔗 Related Issues
implements #16201 for Python
fixes #16117
fixes #13095
💥 What does this PR do?
This PR adds the
--enable-chrome-logs
argument when starting chromedriver. This allows it to inherit the i/o streams from the browser process. Without this, we have no way to suppress or redirect browser i/o streams, which results in unwanted logging going to the user's console.🔧 Implementation Notes
I added this to the chrome Service class rather than the chromium Service class because I am not sure if this is also supported by Edge, or is only relevant to Chrome.
💡 Additional Considerations
We should test to make sure this doesn't screw up any other logging features.
🔄 Types of changes
PR Type
Bug fix
Description
Add
--enable-chrome-logs
flag to Chrome service argumentsEnable browser I/O stream inheritance to suppress unwanted console logging
Override
command_line_args()
method in Chrome service classDiagram Walkthrough
File Walkthrough
service.py
Add Chrome logs flag to service arguments
py/selenium/webdriver/chrome/service.py
command_line_args()
method to include--enable-chrome-logs
flag