Skip to content

Conversation

cgoldberg
Copy link
Contributor

@cgoldberg cgoldberg commented Aug 18, 2025

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

  • 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 method"]
  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 args in command line arguments
  • Enable browser I/O stream inheritance for Chrome driver
+3/-0     

Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Backward Compatibility

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.

def command_line_args(self) -> list[str]:
    return ["--enable-chrome-logs", f"--port={self.port}"] + self._service_args
Argument Ordering

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.

def command_line_args(self) -> list[str]:
    return ["--enable-chrome-logs", f"--port={self.port}"] + self._service_args

Copy link
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Ensure port precedence and None safety

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.

py/selenium/webdriver/chrome/service.py [57-58]

 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.

High
  • More

@cgoldberg
Copy link
Contributor Author

Marking this as a draft. It seems to break things if you launch with --enable-chrome-logs but don't redirect i/o.

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