Skip to content

Commit dcf241b

Browse files
committed
fix: preserve query and fragment in WebSocket URL for tabs
1 parent 99e0f9f commit dcf241b

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

pydoll/browser/chromium/base.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -821,14 +821,21 @@ def _get_tab_kwargs(self, target_id: str, browser_context_id: Optional[str] = No
821821

822822
def _get_tab_ws_address(self, tab_id: str) -> str:
823823
"""
824-
Get WebSocket address for tab. If tab_id is not provided,
825-
it will be derived from the targets.
824+
Get WebSocket address for a specific tab, preserving any query or fragment
825+
components present in the original browser-level WebSocket URL.
826+
827+
This ensures authentication tokens passed via query string (e.g.,
828+
ws://host/devtools/browser/abc?token=XYZ) are retained when switching
829+
to the page-level endpoint (devtools/page/<tab_id>), which is critical
830+
for providers like Browserless or authenticated CDP proxies.
826831
"""
827832
if not self._ws_address:
828833
raise InvalidWebSocketAddress('WebSocket address is not set')
829834

830-
ws_domain = '/'.join(self._ws_address.split('/')[:3])
831-
return f'{ws_domain}/devtools/page/{tab_id}'
835+
parts = urlsplit(self._ws_address)
836+
# Preserve scheme and netloc; build the page path and keep query/fragment
837+
page_path = f'/devtools/page/{tab_id}'
838+
return urlunsplit((parts.scheme, parts.netloc, page_path, parts.query, parts.fragment))
832839

833840
@staticmethod
834841
def _sanitize_proxy_and_extract_auth(

pydoll/browser/managers/browser_process_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def start_browser_process(
5555
@staticmethod
5656
def _default_process_creator(command: list[str]) -> subprocess.Popen:
5757
"""Create browser process with output capture to prevent console clutter."""
58-
return subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
58+
return subprocess.Popen(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
5959

6060
def stop_process(self):
6161
"""

0 commit comments

Comments
 (0)