Skip to content

Commit 712367f

Browse files
committed
Update v1.55.0
Fixes #75
1 parent 1b27246 commit 712367f

File tree

3 files changed

+44
-27
lines changed

3 files changed

+44
-27
lines changed

.github/workflows/patchright_workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
- name: Install Playwright-Python Package
6262
if: steps.version_check.outputs.proceed == 'true'
6363
run: |
64-
git clone https://github.com/microsoft/playwright-python --branch ${{ env.playwright_version }}
64+
git clone https://github.com/microsoft/playwright-python --branch ${{ env.playwright_version }}
6565
cd playwright-python
6666
python -m pip install --upgrade pip
6767
pip install -r local-requirements.txt

patch_python_package.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import toml
66

77
patchright_version = os.environ.get('playwright_version')
8-
patchright_version = "1.52.5"
8+
patchright_version = "1.55.0"
99

1010
def patch_file(file_path: str, patched_tree: ast.AST) -> None:
1111
with open(file_path, "w") as f:
@@ -288,11 +288,11 @@ async def route_handler(route: Route) -> None:
288288
try:
289289
if route.request.resource_type == "document" and route.request.url.startswith("http"):
290290
protocol = route.request.url.split(":")[0]
291-
await route.continue_(url=f"{protocol}://patchright-init-script-inject.internal/")
291+
await route.fallback(url=f"{protocol}://patchright-init-script-inject.internal/")
292292
else:
293-
await route.continue_()
293+
await route.fallback()
294294
except:
295-
await route.continue_()
295+
await route.fallback()
296296
297297
if not self.route_injecting:
298298
if self._connection._is_sync:
@@ -342,11 +342,11 @@ async def route_handler(route: Route) -> None:
342342
try:
343343
if route.request.resource_type == "document" and route.request.url.startswith("http"):
344344
protocol = route.request.url.split(":")[0]
345-
await route.continue_(url=f"{protocol}://patchright-init-script-inject.internal/")
345+
await route.fallback(url=f"{protocol}://patchright-init-script-inject.internal/")
346346
else:
347-
await route.continue_()
347+
await route.fallback()
348348
except:
349-
await route.continue_()
349+
await route.fallback()
350350
351351
if not self.route_injecting and not self.context.route_injecting:
352352
if self._connection._is_sync:
@@ -412,6 +412,15 @@ async def route_handler(route: Route) -> None:
412412

413413
patch_file("playwright-python/playwright/_impl/_clock.py", clock_tree)
414414

415+
# Patching playwright/_impl/_tracing.py
416+
with open("playwright-python/playwright/_impl/_tracing.py") as f:
417+
tracing_source = f.read()
418+
tracing_tree = ast.parse(tracing_source)
419+
420+
for node in ast.walk(tracing_tree):
421+
if isinstance(node, ast.AsyncFunctionDef) and node.name == "start":
422+
node.body.insert(0, ast.parse("await self._parent.install_inject_route()"))
423+
415424
# Patching playwright/async_api/_generated.py
416425
with open("playwright-python/playwright/async_api/_generated.py") as f:
417426
async_generated_source = f.read()

utils/modify_tests.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
# Console Domain Disabled
77
'test_console.py',
88

9-
# query_selector is deprecated
10-
'test_queryselector.py',
11-
'test_element_handle.py',
12-
'test_element_handle_wait_for_element_state.py',
13-
149
# https://github.com/Kaliiiiiiiiii-Vinyzu/patchright/issues/31
1510
'test_route_web_socket.py'
1611
]
@@ -52,14 +47,12 @@
5247
# Disable Popup Blocking
5348
"test_page_event_should_have_an_opener",
5449

55-
# query_selector is deprecated
56-
"test_should_work_with_layout_selectors",
57-
"test_should_dispatch_click_event_element_handle",
58-
"test_should_dispatch_drag_and_drop_events_element_handle",
59-
6050
# Minor Differences in Call Log. Deemed Unimportant
6151
"test_should_be_attached_fail_with_not",
6252
"test_add_script_tag_should_include_source_url_when_path_is_provided",
53+
# / Black Formatting
54+
"test_should_collect_sources",
55+
"test_should_record_trace_with_source",
6356

6457
# Server/Client Header Mismatch
6558
"test_should_report_request_headers_array",
@@ -69,15 +62,10 @@
6962

7063
dont_isolate_evaluation_tests = [
7164
"test_timeout_waiting_for_stable_position",
72-
"test_jshandle_evaluate_accept_object_handle_as_argument",
73-
"test_jshandle_evaluate_accept_nested_handle",
74-
"test_jshandle_evaluate_accept_nested_window_handle",
75-
"test_jshandle_evaluate_accept_multiple_nested_handles",
76-
"test_should_dispatch_drag_drop_events",
77-
"test_should_dispatch_drag_and_drop_events_element_handle",
7865
"track_events",
79-
"captureLastKeydown",
8066
"test_expose_function_should_work_on_frames_before_navigation",
67+
"test_should_dispatch_drag_drop_events",
68+
"test_should_dispatch_drag_and_drop_events_element_handle",
8169
]
8270

8371
# Reason for skipping tests_backup
@@ -131,10 +119,14 @@ def process_file(file_path):
131119
test_name = current_node.name
132120

133121
if test_name in dont_isolate_evaluation_tests:
134-
# Don't add isolated_context=False to these tests
122+
# # Don't add isolated_context=False to these tests
135123
continue
136124

137-
if node.func.attr in ("evaluate", "evaluate_handle", "evaluate_all") and isinstance(node.func.value, ast.Name) and node.func.value.id in ("page", "popup", "button", "new_page", "page1", "page2", "target", "page_1", "page_2", "frame"):
125+
if (node.func.attr in ("evaluate", "evaluate_handle", "evaluate_all")
126+
and isinstance(node.func.value, ast.Name)
127+
and node.func.value.id in ("page", "popup", "button", "new_page", "page1", "page2", "target", "page_1", "page_2", "frame")
128+
and not (node.func.value.id == "button" and "element_handle" in file_path)
129+
):
138130
node.keywords.append(ast.keyword(arg='isolated_context', value=ast.Constant(value=False)))
139131

140132
modified_source = ast.unparse(ast.fix_missing_locations(file_tree))
@@ -213,5 +205,21 @@ def main():
213205
if file.endswith('.py'):
214206
process_file(file_path)
215207

208+
if file == "test_queryselector.py":
209+
with open(file_path, 'r', encoding='utf-8') as f:
210+
content = f.read()
211+
212+
# Replace the full quoted strings with valid Python expressions (not strings)
213+
content = content.replace(
214+
"assert await page.eval_on_selector_all('isolated=ignored', 'es => window.__answer !== undefined')",
215+
"""await page.evaluate('() => window.__answer = document.querySelector("span")', isolated_context=True)\n assert await page.eval_on_selector_all('isolated=ignored', 'es => window.__answer !== undefined')"""
216+
).replace(
217+
"assert page.eval_on_selector_all('isolated=ignored', 'es => window.__answer !== undefined')",
218+
"""page.evaluate('() => window.__answer = document.querySelector("span")', isolated_context=True)\n assert page.eval_on_selector_all('isolated=ignored', 'es => window.__answer !== undefined')"""
219+
)
220+
221+
with open(file_path, 'w', encoding='utf-8') as f:
222+
f.write(content)
223+
216224
if __name__ == '__main__':
217225
main()

0 commit comments

Comments
 (0)