File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 4444 locals_to_params ,
4545)
4646from playwright ._impl ._json_pipe import JsonPipeTransport
47+ from playwright ._impl ._network import serialize_headers
4748from playwright ._impl ._wait_helper import throw_on_timeout
4849
4950if 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 )
Original file line number Diff line number Diff line change 1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ import asyncio
1516from typing import Dict
1617
1718import pytest
1819import requests
1920
20- from playwright .async_api import BrowserType
21+ from playwright .async_api import BrowserType , Error
2122from tests .server import Server , find_free_port
2223
2324pytestmark = 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"
You can’t perform that action at this time.
0 commit comments