Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit731b539

Browse files
authored
chore: implement Request.service_worker (#3013)
1 parent2d30755 commit731b539

File tree

5 files changed

+58
-3
lines changed

5 files changed

+58
-3
lines changed

‎playwright/_impl/_network.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
fromplaywright._impl._browser_contextimportBrowserContext
6767
fromplaywright._impl._fetchimportAPIResponse
6868
fromplaywright._impl._frameimportFrame
69-
fromplaywright._impl._pageimportPage
69+
fromplaywright._impl._pageimportPage,Worker
7070

7171

7272
classFallbackOverrideParameters(TypedDict,total=False):
@@ -184,6 +184,13 @@ def url(self) -> str:
184184
defresource_type(self)->str:
185185
returnself._initializer["resourceType"]
186186

187+
@property
188+
defservice_worker(self)->Optional["Worker"]:
189+
returncast(
190+
Optional["Worker"],
191+
from_nullable_channel(self._initializer.get("serviceWorker")),
192+
)
193+
187194
@property
188195
defmethod(self)->str:
189196
returncast(str,self._fallback_overrides.methodorself._initializer["method"])

‎playwright/async_api/_generated.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,24 @@ def resource_type(self) -> str:
113113
"""
114114
return mapping.from_maybe_impl(self._impl_obj.resource_type)
115115

116+
@property
117+
def service_worker(self) -> typing.Optional["Worker"]:
118+
"""Request.service_worker
119+
120+
The Service `Worker` that is performing the request.
121+
122+
**Details**
123+
124+
This method is Chromium only. It's safe to call when using other browsers, but it will always be `null`.
125+
126+
Requests originated in a Service Worker do not have a `request.frame()` available.
127+
128+
Returns
129+
-------
130+
Union[Worker, None]
131+
"""
132+
return mapping.from_impl_nullable(self._impl_obj.service_worker)
133+
116134
@property
117135
def method(self) -> str:
118136
"""Request.method

‎playwright/sync_api/_generated.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,24 @@ def resource_type(self) -> str:
113113
"""
114114
return mapping.from_maybe_impl(self._impl_obj.resource_type)
115115

116+
@property
117+
def service_worker(self) -> typing.Optional["Worker"]:
118+
"""Request.service_worker
119+
120+
The Service `Worker` that is performing the request.
121+
122+
**Details**
123+
124+
This method is Chromium only. It's safe to call when using other browsers, but it will always be `null`.
125+
126+
Requests originated in a Service Worker do not have a `request.frame()` available.
127+
128+
Returns
129+
-------
130+
Union[Worker, None]
131+
"""
132+
return mapping.from_impl_nullable(self._impl_obj.service_worker)
133+
116134
@property
117135
def method(self) -> str:
118136
"""Request.method

‎setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
importzipfile
2222
fromtypingimportDict
2323

24-
driver_version="1.57.0"
24+
driver_version="1.57.0-beta-1764944708000"
2525

2626
base_wheel_bundles= [
2727
{

‎tests/sync/test_network.py‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def handle_request(route: Route) -> None:
9292
assertresponse.json()== {"foo":"bar"}
9393

9494

95-
deftest_should_report_if_request_was_from_service_worker(
95+
deftest_should_report_if_response_was_from_service_worker(
9696
page:Page,server:Server
9797
)->None:
9898
response=page.goto(server.PREFIX+"/serviceworkers/fetch/sw.html")
@@ -102,3 +102,15 @@ def test_should_report_if_request_was_from_service_worker(
102102
withpage.expect_response("**/example.txt")asresponse_info:
103103
page.evaluate("() => fetch('/example.txt')")
104104
assertresponse_info.value.from_service_worker
105+
106+
107+
@pytest.mark.only_browser("chromium")
108+
deftest_should_report_service_worker_request(page:Page,server:Server)->None:
109+
withpage.context.expect_event("serviceworker")asworker_info:
110+
page.goto(server.PREFIX+"/serviceworkers/fetch/sw.html")
111+
page.evaluate("() => window.activationPromise")
112+
withpage.context.expect_event(
113+
"request",lambdar:r.service_workerisnotNone
114+
)asrequest_info:
115+
page.evaluate("() => fetch('/example.txt')")
116+
assertrequest_info.value.service_worker==worker_info.value

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp