File tree 2 files changed +16
-1
lines changed 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 44
44
locals_to_params ,
45
45
)
46
46
from playwright ._impl ._json_pipe import JsonPipeTransport
47
+ from playwright ._impl ._network import serialize_headers
47
48
from playwright ._impl ._wait_helper import throw_on_timeout
48
49
49
50
if TYPE_CHECKING :
@@ -166,6 +167,8 @@ async def connect_over_cdp(
166
167
headers : Dict [str , str ] = None ,
167
168
) -> Browser :
168
169
params = locals_to_params (locals ())
170
+ if params .get ("headers" ):
171
+ params ["headers" ] = serialize_headers (params ["headers" ])
169
172
response = await self ._channel .send_return_as_dict ("connectOverCDP" , params )
170
173
browser = cast (Browser , from_channel (response ["browser" ]))
171
174
self ._did_launch_browser (browser )
Original file line number Diff line number Diff line change 12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
+ import asyncio
15
16
from typing import Dict
16
17
17
18
import pytest
18
19
import requests
19
20
20
- from playwright .async_api import BrowserType
21
+ from playwright .async_api import BrowserType , Error
21
22
from tests .server import Server , find_free_port
22
23
23
24
pytestmark = pytest .mark .only_browser ("chromium" )
@@ -86,3 +87,14 @@ async def test_conect_over_a_ws_endpoint(
86
87
assert len (cdp_browser2 .contexts ) == 1
87
88
await cdp_browser2 .close ()
88
89
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