Skip to content

Commit 572a78a

Browse files
authored
fix: make it possible to send connect_over_cdp headers (microsoft#1912)
1 parent 9f73b88 commit 572a78a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

playwright/_impl/_browser_type.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
locals_to_params,
4545
)
4646
from playwright._impl._json_pipe import JsonPipeTransport
47+
from playwright._impl._network import serialize_headers
4748
from playwright._impl._wait_helper import throw_on_timeout
4849

4950
if TYPE_CHECKING:
@@ -166,6 +167,8 @@ async def connect_over_cdp(
166167
headers: Dict[str, str] = None,
167168
) -> Browser:
168169
params = locals_to_params(locals())
170+
if params.get("headers"):
171+
params["headers"] = serialize_headers(params["headers"])
169172
response = await self._channel.send_return_as_dict("connectOverCDP", params)
170173
browser = cast(Browser, from_channel(response["browser"]))
171174
self._did_launch_browser(browser)

tests/async/test_browsertype_connect_cdp.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import asyncio
1516
from typing import Dict
1617

1718
import pytest
1819
import requests
1920

20-
from playwright.async_api import BrowserType
21+
from playwright.async_api import BrowserType, Error
2122
from tests.server import Server, find_free_port
2223

2324
pytestmark = pytest.mark.only_browser("chromium")
@@ -86,3 +87,14 @@ async def test_conect_over_a_ws_endpoint(
8687
assert len(cdp_browser2.contexts) == 1
8788
await cdp_browser2.close()
8889
await browser_server.close()
90+
91+
92+
async def test_connect_over_cdp_passing_header_works(
93+
launch_arguments: Dict, browser_type: BrowserType, server: Server
94+
):
95+
request = asyncio.create_task(server.wait_for_request("/ws"))
96+
with pytest.raises(Error):
97+
await browser_type.connect_over_cdp(
98+
f"ws://127.0.0.1:{server.PORT}/ws", headers={"foo": "bar"}
99+
)
100+
assert (await request).getHeader("foo") == "bar"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy