pymobiledevice3 5.0.0__py3-none-any.whl → 5.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pymobiledevice3 might be problematic. Click here for more details.
- misc/plist_sniffer.py +15 -15
- misc/remotexpc_sniffer.py +29 -28
- pymobiledevice3/__main__.py +128 -102
- pymobiledevice3/_version.py +2 -2
- pymobiledevice3/bonjour.py +26 -49
- pymobiledevice3/ca.py +32 -24
- pymobiledevice3/cli/activation.py +7 -7
- pymobiledevice3/cli/afc.py +19 -19
- pymobiledevice3/cli/amfi.py +4 -4
- pymobiledevice3/cli/apps.py +51 -39
- pymobiledevice3/cli/backup.py +58 -32
- pymobiledevice3/cli/bonjour.py +25 -18
- pymobiledevice3/cli/cli_common.py +112 -81
- pymobiledevice3/cli/companion_proxy.py +4 -4
- pymobiledevice3/cli/completions.py +10 -10
- pymobiledevice3/cli/crash.py +37 -31
- pymobiledevice3/cli/developer.py +602 -520
- pymobiledevice3/cli/diagnostics.py +38 -33
- pymobiledevice3/cli/lockdown.py +79 -74
- pymobiledevice3/cli/mounter.py +85 -68
- pymobiledevice3/cli/notification.py +10 -10
- pymobiledevice3/cli/pcap.py +19 -14
- pymobiledevice3/cli/power_assertion.py +12 -10
- pymobiledevice3/cli/processes.py +10 -10
- pymobiledevice3/cli/profile.py +88 -77
- pymobiledevice3/cli/provision.py +17 -17
- pymobiledevice3/cli/remote.py +186 -110
- pymobiledevice3/cli/restore.py +43 -40
- pymobiledevice3/cli/springboard.py +30 -28
- pymobiledevice3/cli/syslog.py +85 -58
- pymobiledevice3/cli/usbmux.py +21 -20
- pymobiledevice3/cli/version.py +3 -2
- pymobiledevice3/cli/webinspector.py +157 -79
- pymobiledevice3/common.py +1 -1
- pymobiledevice3/exceptions.py +154 -60
- pymobiledevice3/irecv.py +49 -53
- pymobiledevice3/irecv_devices.py +1489 -492
- pymobiledevice3/lockdown.py +394 -241
- pymobiledevice3/lockdown_service_provider.py +5 -7
- pymobiledevice3/osu/os_utils.py +18 -9
- pymobiledevice3/osu/posix_util.py +28 -15
- pymobiledevice3/osu/win_util.py +14 -8
- pymobiledevice3/pair_records.py +19 -19
- pymobiledevice3/remote/common.py +4 -4
- pymobiledevice3/remote/core_device/app_service.py +94 -67
- pymobiledevice3/remote/core_device/core_device_service.py +17 -14
- pymobiledevice3/remote/core_device/device_info.py +5 -5
- pymobiledevice3/remote/core_device/diagnostics_service.py +10 -8
- pymobiledevice3/remote/core_device/file_service.py +47 -33
- pymobiledevice3/remote/remote_service_discovery.py +53 -35
- pymobiledevice3/remote/remotexpc.py +62 -41
- pymobiledevice3/remote/tunnel_service.py +371 -293
- pymobiledevice3/remote/utils.py +12 -11
- pymobiledevice3/remote/xpc_message.py +145 -125
- pymobiledevice3/resources/dsc_uuid_map.py +19 -19
- pymobiledevice3/resources/firmware_notifications.py +16 -16
- pymobiledevice3/restore/asr.py +27 -27
- pymobiledevice3/restore/base_restore.py +90 -47
- pymobiledevice3/restore/consts.py +87 -66
- pymobiledevice3/restore/device.py +11 -11
- pymobiledevice3/restore/fdr.py +46 -46
- pymobiledevice3/restore/ftab.py +19 -19
- pymobiledevice3/restore/img4.py +130 -133
- pymobiledevice3/restore/mbn.py +35 -54
- pymobiledevice3/restore/recovery.py +125 -135
- pymobiledevice3/restore/restore.py +524 -523
- pymobiledevice3/restore/restore_options.py +122 -115
- pymobiledevice3/restore/restored_client.py +25 -22
- pymobiledevice3/restore/tss.py +378 -270
- pymobiledevice3/service_connection.py +50 -46
- pymobiledevice3/services/accessibilityaudit.py +136 -126
- pymobiledevice3/services/afc.py +350 -291
- pymobiledevice3/services/amfi.py +21 -18
- pymobiledevice3/services/companion.py +23 -19
- pymobiledevice3/services/crash_reports.py +60 -46
- pymobiledevice3/services/debugserver_applist.py +3 -3
- pymobiledevice3/services/device_arbitration.py +8 -8
- pymobiledevice3/services/device_link.py +55 -47
- pymobiledevice3/services/diagnostics.py +971 -968
- pymobiledevice3/services/dtfetchsymbols.py +8 -8
- pymobiledevice3/services/dvt/dvt_secure_socket_proxy.py +4 -4
- pymobiledevice3/services/dvt/dvt_testmanaged_proxy.py +4 -4
- pymobiledevice3/services/dvt/instruments/activity_trace_tap.py +85 -74
- pymobiledevice3/services/dvt/instruments/application_listing.py +2 -3
- pymobiledevice3/services/dvt/instruments/condition_inducer.py +7 -6
- pymobiledevice3/services/dvt/instruments/core_profile_session_tap.py +466 -384
- pymobiledevice3/services/dvt/instruments/device_info.py +11 -11
- pymobiledevice3/services/dvt/instruments/energy_monitor.py +1 -1
- pymobiledevice3/services/dvt/instruments/graphics.py +1 -1
- pymobiledevice3/services/dvt/instruments/location_simulation.py +1 -1
- pymobiledevice3/services/dvt/instruments/location_simulation_base.py +10 -10
- pymobiledevice3/services/dvt/instruments/network_monitor.py +17 -17
- pymobiledevice3/services/dvt/instruments/notifications.py +1 -1
- pymobiledevice3/services/dvt/instruments/process_control.py +25 -10
- pymobiledevice3/services/dvt/instruments/screenshot.py +2 -2
- pymobiledevice3/services/dvt/instruments/sysmontap.py +15 -15
- pymobiledevice3/services/dvt/testmanaged/xcuitest.py +40 -50
- pymobiledevice3/services/file_relay.py +10 -10
- pymobiledevice3/services/heartbeat.py +8 -7
- pymobiledevice3/services/house_arrest.py +12 -15
- pymobiledevice3/services/installation_proxy.py +119 -100
- pymobiledevice3/services/lockdown_service.py +12 -5
- pymobiledevice3/services/misagent.py +22 -19
- pymobiledevice3/services/mobile_activation.py +84 -72
- pymobiledevice3/services/mobile_config.py +330 -301
- pymobiledevice3/services/mobile_image_mounter.py +137 -116
- pymobiledevice3/services/mobilebackup2.py +188 -150
- pymobiledevice3/services/notification_proxy.py +11 -11
- pymobiledevice3/services/os_trace.py +69 -51
- pymobiledevice3/services/pcapd.py +306 -306
- pymobiledevice3/services/power_assertion.py +10 -9
- pymobiledevice3/services/preboard.py +4 -4
- pymobiledevice3/services/remote_fetch_symbols.py +16 -14
- pymobiledevice3/services/remote_server.py +176 -146
- pymobiledevice3/services/restore_service.py +16 -16
- pymobiledevice3/services/screenshot.py +13 -10
- pymobiledevice3/services/simulate_location.py +7 -7
- pymobiledevice3/services/springboard.py +15 -15
- pymobiledevice3/services/syslog.py +5 -5
- pymobiledevice3/services/web_protocol/alert.py +3 -3
- pymobiledevice3/services/web_protocol/automation_session.py +180 -176
- pymobiledevice3/services/web_protocol/cdp_screencast.py +44 -36
- pymobiledevice3/services/web_protocol/cdp_server.py +19 -19
- pymobiledevice3/services/web_protocol/cdp_target.py +411 -373
- pymobiledevice3/services/web_protocol/driver.py +47 -45
- pymobiledevice3/services/web_protocol/element.py +74 -63
- pymobiledevice3/services/web_protocol/inspector_session.py +106 -102
- pymobiledevice3/services/web_protocol/selenium_api.py +2 -2
- pymobiledevice3/services/web_protocol/session_protocol.py +15 -10
- pymobiledevice3/services/web_protocol/switch_to.py +11 -12
- pymobiledevice3/services/webinspector.py +127 -116
- pymobiledevice3/tcp_forwarder.py +35 -22
- pymobiledevice3/tunneld/api.py +20 -15
- pymobiledevice3/tunneld/server.py +212 -133
- pymobiledevice3/usbmux.py +183 -138
- pymobiledevice3/utils.py +14 -11
- {pymobiledevice3-5.0.0.dist-info → pymobiledevice3-5.0.2.dist-info}/METADATA +1 -1
- pymobiledevice3-5.0.2.dist-info/RECORD +173 -0
- pymobiledevice3-5.0.0.dist-info/RECORD +0 -173
- {pymobiledevice3-5.0.0.dist-info → pymobiledevice3-5.0.2.dist-info}/WHEEL +0 -0
- {pymobiledevice3-5.0.0.dist-info → pymobiledevice3-5.0.2.dist-info}/entry_points.txt +0 -0
- {pymobiledevice3-5.0.0.dist-info → pymobiledevice3-5.0.2.dist-info}/licenses/LICENSE +0 -0
- {pymobiledevice3-5.0.0.dist-info → pymobiledevice3-5.0.2.dist-info}/top_level.txt +0 -0
|
@@ -9,60 +9,75 @@ from pymobiledevice3.services.web_protocol.cdp_screencast import ScreenCast
|
|
|
9
9
|
|
|
10
10
|
logger = logging.getLogger(__name__)
|
|
11
11
|
|
|
12
|
-
NETWORK_RESOURCE_TYPES = [
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
NETWORK_RESOURCE_TYPES = [
|
|
13
|
+
"Document",
|
|
14
|
+
"Stylesheet",
|
|
15
|
+
"Image",
|
|
16
|
+
"Media",
|
|
17
|
+
"Font",
|
|
18
|
+
"Script",
|
|
19
|
+
"TextTrack",
|
|
20
|
+
"XHR",
|
|
21
|
+
"Fetch",
|
|
22
|
+
"EventSource",
|
|
23
|
+
"WebSocket",
|
|
24
|
+
"Manifest",
|
|
25
|
+
"SignedExchange",
|
|
26
|
+
"Ping",
|
|
27
|
+
"CSPViolationReport",
|
|
28
|
+
"Preflight",
|
|
29
|
+
"Other",
|
|
30
|
+
]
|
|
15
31
|
|
|
16
32
|
LOG_MESSAGE_SOURCES = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
"xml": "xml",
|
|
34
|
+
"javascript": "javascript",
|
|
35
|
+
"network": "network",
|
|
36
|
+
"console-api": "javascript",
|
|
37
|
+
"storage": "storage",
|
|
38
|
+
"appcache": "appcache",
|
|
39
|
+
"rendering": "rendering",
|
|
40
|
+
"css": "rendering",
|
|
41
|
+
"security": "security",
|
|
42
|
+
"deprecation": "deprecation",
|
|
43
|
+
"worker": "worker",
|
|
44
|
+
"violation": "violation",
|
|
45
|
+
"intervention": "intervention",
|
|
46
|
+
"recommendation": "recommendation",
|
|
47
|
+
"other": "other",
|
|
48
|
+
"content-blocker": "other",
|
|
49
|
+
"media": "other",
|
|
50
|
+
"mediasource": "other",
|
|
51
|
+
"webrtc": "other",
|
|
52
|
+
"itp-debug": "other",
|
|
53
|
+
"ad-click-attribution": "other",
|
|
38
54
|
}
|
|
39
55
|
|
|
40
56
|
LOG_MESSAGE_LEVELS = {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
57
|
+
"log": "info",
|
|
58
|
+
"info": "info",
|
|
59
|
+
"warning": "warning",
|
|
60
|
+
"error": "error",
|
|
61
|
+
"debug": "verbose",
|
|
47
62
|
}
|
|
48
63
|
|
|
49
64
|
DEBUGGER_PAUSED_REASON = {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
"XHR": "XHR",
|
|
66
|
+
"Fetch": "other",
|
|
67
|
+
"DOM": "DOM",
|
|
68
|
+
"AnimationFrame": "other",
|
|
69
|
+
"Interval": "other",
|
|
70
|
+
"Listener": "EventListener",
|
|
71
|
+
"Timeout": "other",
|
|
72
|
+
"exception": "exception",
|
|
73
|
+
"assert": "assert",
|
|
74
|
+
"CSPViolation": "CSPViolation",
|
|
75
|
+
"DebuggerStatement": "debugCommand",
|
|
76
|
+
"Breakpoint": "instrumentation",
|
|
77
|
+
"PauseOnNextStatement": "instrumentation",
|
|
78
|
+
"Microtask": "other",
|
|
79
|
+
"BlackboxedScript": "other",
|
|
80
|
+
"other": "other",
|
|
66
81
|
}
|
|
67
82
|
|
|
68
83
|
|
|
@@ -82,77 +97,76 @@ class CdpTarget:
|
|
|
82
97
|
self.input_queue = asyncio.Queue()
|
|
83
98
|
self.screencast = None
|
|
84
99
|
self.from_cdp_special_messages_methods = {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
100
|
+
"Audits.enable": self._audits_enable,
|
|
101
|
+
"DOM.getBoxModel": self._dom_get_box_model,
|
|
102
|
+
"DOM.enable": partial(self._simple_response, value=None),
|
|
103
|
+
"DOM.getNodeForLocation": self._dom_get_node_for_location,
|
|
104
|
+
"DOM.getNodesForSubtreeByStyle": self._dom_get_nodes_for_subtree_by_style,
|
|
105
|
+
"Log.clear": self._log_clear,
|
|
106
|
+
"Log.disable": self._log_disable,
|
|
107
|
+
"Log.enable": self._log_enable,
|
|
108
|
+
"Log.startViolationsReport": partial(self._simple_response, value=None),
|
|
109
|
+
"Page.getNavigationHistory": self._page_get_navigation_history,
|
|
110
|
+
"Page.startScreencast": self._page_start_screencast,
|
|
111
|
+
"Page.stopScreencast": self._page_stop_screencast,
|
|
112
|
+
"Page.screencastFrameAck": self._page_screencast_frame_ack,
|
|
113
|
+
"Page.getResourceTree": self._page_get_resource_tree,
|
|
114
|
+
"Emulation.setEmulatedMedia": self._emulation_set_emulated_media,
|
|
115
|
+
"Emulation.setTouchEmulationEnabled": partial(self._simple_response, value=None),
|
|
116
|
+
"Emulation.setFocusEmulationEnabled": partial(self._simple_response, value=None),
|
|
117
|
+
"Emulation.setEmulatedVisionDeficiency": partial(self._simple_response, value=None),
|
|
118
|
+
"Emulation.setAutoDarkModeOverride": self._emulation_set_auto_dark_mode_override,
|
|
119
|
+
"Emulation.setEmitTouchEventsForMouse": partial(self._simple_response, value=None),
|
|
120
|
+
"Debugger.setAsyncCallStackDepth": partial(self._simple_response, value=True),
|
|
121
|
+
"Debugger.setBlackboxPatterns": self._debugger_set_blackbox_patterns,
|
|
122
|
+
"Debugger.setBreakpointByUrl": self._debugger_set_breakpoint_by_url,
|
|
123
|
+
"DOMDebugger.setBreakOnCSPViolation": partial(self._simple_response, value=None),
|
|
124
|
+
"DOMDebugger.getEventListeners": self._domdebugger_get_event_listeners,
|
|
125
|
+
"Network.setCacheDisabled": self._network_set_cache_disabled,
|
|
126
|
+
"Network.loadNetworkResource": self._network_load_network_resource,
|
|
127
|
+
"Network.setAttachDebugStack": partial(self._simple_response, value=None),
|
|
128
|
+
"Network.clearAcceptedEncodingsOverride": partial(self._simple_response, value=None),
|
|
129
|
+
"ServiceWorker.enable": self._service_worker_enable,
|
|
130
|
+
"HeapProfiler.enable": partial(self._simple_response, value=None),
|
|
131
|
+
"Overlay.setShowGridOverlays": partial(self._simple_response, value=None),
|
|
132
|
+
"Overlay.setShowFlexOverlays": partial(self._simple_response, value=None),
|
|
133
|
+
"Overlay.setShowScrollSnapOverlays": partial(self._simple_response, value=None),
|
|
134
|
+
"Overlay.setShowContainerQueryOverlays": partial(self._simple_response, value=None),
|
|
135
|
+
"Overlay.setShowIsolatedElements": partial(self._simple_response, value=None),
|
|
136
|
+
"Overlay.hideHighlight": partial(self._simple_response, value=None),
|
|
137
|
+
"Overlay.highlightNode": self._overlay_highlight_node,
|
|
138
|
+
"Overlay.enable": partial(self._simple_response, value=None),
|
|
139
|
+
"Overlay.setShowViewportSizeOnResize": partial(self._simple_response, value=None),
|
|
140
|
+
"Overlay.setPausedInDebuggerMessage": partial(self._simple_response, value=None),
|
|
141
|
+
"Runtime.runIfWaitingForDebugger": partial(self._simple_response, value=None),
|
|
142
|
+
"Runtime.compileScript": self._runtime_compile_script,
|
|
143
|
+
"Runtime.getIsolateId": self._runtime_get_isolate_id,
|
|
144
|
+
"Profiler.enable": partial(self._simple_response, value=None),
|
|
145
|
+
"Target.setAutoAttach": self._target_set_auto_attach,
|
|
146
|
+
"Target.setDiscoverTargets": partial(self._simple_response, value=None),
|
|
147
|
+
"Target.setRemoteLocations": partial(self._simple_response, value=None),
|
|
148
|
+
"CSS.trackComputedStyleUpdates": partial(self._simple_response, value=None),
|
|
149
|
+
"CSS.takeComputedStyleUpdates": self._css_take_computed_style_updates,
|
|
150
|
+
"CSS.addRule": self._css_add_rule,
|
|
151
|
+
"Input.emulateTouchFromMouseEvent": self._input_emulate_touch_from_mouse_event,
|
|
152
|
+
"Input.dispatchKeyEvent": self._input_dispatch_key_event,
|
|
139
153
|
}
|
|
140
154
|
self.to_cdp_special_messages_methods = {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
155
|
+
"Target.targetCreated": self._target_created,
|
|
156
|
+
"Target.targetDestroyed": self._target_destroyed,
|
|
157
|
+
"Target.dispatchMessageFromTarget": self._target_dispatch_message_from_target,
|
|
158
|
+
"Target.didCommitProvisionalTarget": self._target_did_commit_provisional_target,
|
|
145
159
|
}
|
|
146
160
|
self.to_cdp_special_dispatched_messages_methods = {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
161
|
+
"Debugger.scriptParsed": self._debugger_script_parsed,
|
|
162
|
+
"Debugger.scriptFailedToParse": self._debugger_script_failed_to_parse,
|
|
163
|
+
"Debugger.paused": self._debugger_paused,
|
|
164
|
+
"Debugger.globalObjectCleared": self._debugger_global_object_cleared,
|
|
165
|
+
"Page.defaultAppearanceDidChange": self._page_default_appearance_did_change,
|
|
166
|
+
"Runtime.executionContextCreated": self._runtime_execution_context_created,
|
|
167
|
+
"Console.messageAdded": self._console_message_added,
|
|
168
|
+
"Network.responseReceived": self._network_response_received,
|
|
169
|
+
"Network.loadingFinished": self._network_loading_finished,
|
|
156
170
|
}
|
|
157
171
|
self._waiting_for_id = 0
|
|
158
172
|
self._input_task = asyncio.create_task(self._input_loop())
|
|
@@ -169,10 +183,10 @@ class CdpTarget:
|
|
|
169
183
|
while not protocol.inspector.wir_events:
|
|
170
184
|
await asyncio.sleep(0)
|
|
171
185
|
created = protocol.inspector.wir_events.pop(0)
|
|
172
|
-
while
|
|
186
|
+
while "targetInfo" not in created["params"]:
|
|
173
187
|
created = protocol.inspector.wir_events.pop(0)
|
|
174
|
-
target_id = created[
|
|
175
|
-
logger.info(f
|
|
188
|
+
target_id = created["params"]["targetInfo"]["targetId"]
|
|
189
|
+
logger.info(f"Created: {target_id}")
|
|
176
190
|
target = cls(protocol, target_id)
|
|
177
191
|
await target.output_queue.put(created)
|
|
178
192
|
return target
|
|
@@ -197,10 +211,10 @@ class CdpTarget:
|
|
|
197
211
|
while True:
|
|
198
212
|
for i in range(len(self.protocol.inspector.wir_events)):
|
|
199
213
|
message = self.protocol.inspector.wir_events[i]
|
|
200
|
-
if message[
|
|
214
|
+
if message["method"] != "Target.dispatchMessageFromTarget":
|
|
201
215
|
continue
|
|
202
|
-
message = json.loads(message[
|
|
203
|
-
if message.get(
|
|
216
|
+
message = json.loads(message["params"]["message"])
|
|
217
|
+
if message.get("id", "") != id_:
|
|
204
218
|
continue
|
|
205
219
|
del self.protocol.inspector.wir_events[i]
|
|
206
220
|
return message
|
|
@@ -211,7 +225,7 @@ class CdpTarget:
|
|
|
211
225
|
Send a message to the target and wait for response.
|
|
212
226
|
"""
|
|
213
227
|
self._waiting_for_id += 1
|
|
214
|
-
await self._send_message_to_target({
|
|
228
|
+
await self._send_message_to_target({"id": id_, "method": method, "params": params})
|
|
215
229
|
result = await self.wait_for_event_id(id_)
|
|
216
230
|
self._waiting_for_id -= 1
|
|
217
231
|
return result
|
|
@@ -220,26 +234,26 @@ class CdpTarget:
|
|
|
220
234
|
"""
|
|
221
235
|
Evaluate Javascript expression.
|
|
222
236
|
"""
|
|
223
|
-
logger.debug(
|
|
224
|
-
params = {
|
|
225
|
-
data = await self.send_message_with_result(id_,
|
|
226
|
-
logger.debug(
|
|
227
|
-
result = data[
|
|
228
|
-
if result[
|
|
229
|
-
return result[
|
|
230
|
-
elif result[
|
|
237
|
+
logger.debug("Evaluating: ", expression)
|
|
238
|
+
params = {"expression": expression}
|
|
239
|
+
data = await self.send_message_with_result(id_, "Runtime.evaluate", params)
|
|
240
|
+
logger.debug("Evaluated: ", data)
|
|
241
|
+
result = data["result"]["result"]
|
|
242
|
+
if result["type"] == "string":
|
|
243
|
+
return result["value"]
|
|
244
|
+
elif result["type"] == "undefined":
|
|
231
245
|
return None
|
|
232
|
-
elif result[
|
|
246
|
+
elif result["type"] == "object":
|
|
233
247
|
return result
|
|
234
248
|
else:
|
|
235
|
-
logger.debug(
|
|
249
|
+
logger.debug("Unknown type: ", result)
|
|
236
250
|
return result
|
|
237
251
|
|
|
238
252
|
async def _input_loop(self):
|
|
239
253
|
while True:
|
|
240
254
|
message = await self.input_queue.get()
|
|
241
|
-
if message[
|
|
242
|
-
await self.from_cdp_special_messages_methods[message[
|
|
255
|
+
if message["method"] in self.from_cdp_special_messages_methods:
|
|
256
|
+
await self.from_cdp_special_messages_methods[message["method"]](message)
|
|
243
257
|
else:
|
|
244
258
|
await self._send_message_to_target(message)
|
|
245
259
|
|
|
@@ -252,106 +266,115 @@ class CdpTarget:
|
|
|
252
266
|
await self._to_output_queue(message)
|
|
253
267
|
|
|
254
268
|
async def _to_output_queue(self, message):
|
|
255
|
-
if message[
|
|
256
|
-
await self.to_cdp_special_messages_methods[message[
|
|
269
|
+
if message["method"] in self.to_cdp_special_messages_methods:
|
|
270
|
+
await self.to_cdp_special_messages_methods[message["method"]](message)
|
|
257
271
|
else:
|
|
258
|
-
logger.error(
|
|
272
|
+
logger.error("Error!!!!!!!!!!!!", message)
|
|
259
273
|
raise RuntimeError()
|
|
260
274
|
|
|
261
275
|
async def _send_message_to_target(self, message):
|
|
262
|
-
await self.protocol.send_command(
|
|
263
|
-
|
|
276
|
+
await self.protocol.send_command(
|
|
277
|
+
"Target.sendMessageToTarget", targetId=self.target_id, message=json.dumps(message)
|
|
278
|
+
)
|
|
264
279
|
|
|
265
280
|
async def _simple_response(self, message, value):
|
|
266
|
-
await self.output_queue.put({
|
|
281
|
+
await self.output_queue.put({"id": message["id"], "result": {"result": value}})
|
|
267
282
|
|
|
268
283
|
async def _audits_enable(self, message):
|
|
269
|
-
message[
|
|
284
|
+
message["method"] = "Audit.setup"
|
|
270
285
|
await self._send_message_to_target(message)
|
|
271
286
|
|
|
272
287
|
async def _dom_get_box_model(self, message):
|
|
273
|
-
message[
|
|
274
|
-
message[
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
288
|
+
message["method"] = "DOM.highlightNode"
|
|
289
|
+
message["params"]["highlightConfig"] = {
|
|
290
|
+
"showInfo": True,
|
|
291
|
+
"contentColor": {"r": 111, "g": 168, "b": 220, "a": 0.66},
|
|
292
|
+
"paddingColor": {"r": 147, "g": 196, "b": 125, "a": 0.55},
|
|
293
|
+
"borderColor": {"r": 255, "g": 229, "b": 153, "a": 0.66},
|
|
294
|
+
"marginColor": {"r": 246, "g": 178, "b": 107, "a": 0.66},
|
|
280
295
|
}
|
|
281
296
|
await self._send_message_to_target(message)
|
|
282
297
|
|
|
283
298
|
async def object_id_to_node_id(self, object_id, id_):
|
|
284
|
-
node = await self.send_message_with_result(id_,
|
|
285
|
-
return node[
|
|
299
|
+
node = await self.send_message_with_result(id_, "DOM.requestNode", {"objectId": object_id})
|
|
300
|
+
return node["result"]["nodeId"]
|
|
286
301
|
|
|
287
302
|
async def _dom_get_node_for_location(self, message):
|
|
288
|
-
x, y = message[
|
|
289
|
-
obj = await self.evaluate_and_result(message[
|
|
290
|
-
if
|
|
303
|
+
x, y = message["params"]["x"], message["params"]["y"]
|
|
304
|
+
obj = await self.evaluate_and_result(message["id"], f"document.elementFromPoint({x},{y})")
|
|
305
|
+
if "objectId" not in obj:
|
|
291
306
|
await self._simple_response(message, None)
|
|
292
307
|
return
|
|
293
|
-
result = {
|
|
294
|
-
await self.output_queue.put({
|
|
308
|
+
result = {"nodeId": await self.object_id_to_node_id(obj["objectId"], message["id"])}
|
|
309
|
+
await self.output_queue.put({"id": message["id"], "result": result})
|
|
295
310
|
|
|
296
311
|
async def _dom_get_nodes_for_subtree_by_style(self, message):
|
|
297
|
-
object_id = (
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
312
|
+
object_id = (
|
|
313
|
+
await self.send_message_with_result(
|
|
314
|
+
message["id"], "DOM.resolveNode", {"nodeId": message["params"]["nodeId"]}
|
|
315
|
+
)
|
|
316
|
+
)["result"]["object"]["objectId"]
|
|
317
|
+
result = await self.send_message_with_result(
|
|
318
|
+
message["id"],
|
|
319
|
+
"Runtime.callFunctionOn",
|
|
320
|
+
{
|
|
321
|
+
"objectId": object_id,
|
|
322
|
+
"functionDeclaration": (
|
|
323
|
+
"function(styles) {"
|
|
324
|
+
" const result = new Set();"
|
|
325
|
+
' var all = this.getElementsByTagName("*");'
|
|
326
|
+
" for (var elem_i=0; elem_i < all.length; elem_i++) {"
|
|
327
|
+
" for (var style_i in styles) {"
|
|
328
|
+
" if (window.getComputedStyle(all[elem_i]).getPropertyValue(styles[style_i].name) ==="
|
|
329
|
+
" styles[style_i].value) {"
|
|
330
|
+
" result.add(all[elem_i]);"
|
|
331
|
+
" break;"
|
|
332
|
+
" }"
|
|
333
|
+
" }"
|
|
334
|
+
" }"
|
|
335
|
+
" return result;"
|
|
336
|
+
"}"
|
|
337
|
+
),
|
|
338
|
+
"arguments": [{"value": message["params"]["computedStyles"]}],
|
|
339
|
+
},
|
|
340
|
+
)
|
|
341
|
+
result = await self.send_message_with_result(
|
|
342
|
+
message["id"], "Runtime.getCollectionEntries", {"objectId": result["result"]["result"]["objectId"]}
|
|
343
|
+
)
|
|
322
344
|
nodes = await asyncio.gather(
|
|
323
|
-
*[
|
|
324
|
-
|
|
345
|
+
*[
|
|
346
|
+
self.object_id_to_node_id(obj["value"]["objectId"], message["id"] - i)
|
|
347
|
+
for i, obj in enumerate(result["result"]["entries"])
|
|
348
|
+
],
|
|
349
|
+
return_exceptions=True,
|
|
350
|
+
)
|
|
325
351
|
nodes = [n for n in nodes if isinstance(n, int)]
|
|
326
|
-
await self.output_queue.put({
|
|
352
|
+
await self.output_queue.put({"id": message["id"], "result": {"nodeIds": nodes}})
|
|
327
353
|
|
|
328
354
|
async def _log_clear(self, message):
|
|
329
|
-
message[
|
|
355
|
+
message["method"] = "Console.clearMessages"
|
|
330
356
|
await self._send_message_to_target(message)
|
|
331
357
|
|
|
332
358
|
async def _log_disable(self, message):
|
|
333
|
-
message[
|
|
359
|
+
message["method"] = "Console.disable"
|
|
334
360
|
await self._send_message_to_target(message)
|
|
335
361
|
|
|
336
362
|
async def _log_enable(self, message):
|
|
337
|
-
message[
|
|
363
|
+
message["method"] = "Console.enable"
|
|
338
364
|
await self._send_message_to_target(message)
|
|
339
365
|
|
|
340
366
|
async def _page_get_navigation_history(self, message):
|
|
341
|
-
href = await self.evaluate_and_result(message[
|
|
342
|
-
title = await self.evaluate_and_result(message[
|
|
367
|
+
href = await self.evaluate_and_result(message["id"], "window.location.href")
|
|
368
|
+
title = await self.evaluate_and_result(message["id"], "document.title")
|
|
343
369
|
await self.output_queue.put({
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
'currentIndex': 0,
|
|
347
|
-
'entries': [{'id': 0, 'url': href, 'title': title}]
|
|
348
|
-
}
|
|
370
|
+
"id": message["id"],
|
|
371
|
+
"result": {"currentIndex": 0, "entries": [{"id": 0, "url": href, "title": title}]},
|
|
349
372
|
})
|
|
350
373
|
|
|
351
374
|
async def _page_start_screencast(self, message):
|
|
352
|
-
params = message[
|
|
353
|
-
self.screencast = ScreenCast(self, params[
|
|
354
|
-
await self.screencast.start(message[
|
|
375
|
+
params = message["params"]
|
|
376
|
+
self.screencast = ScreenCast(self, params["format"], params["quality"], params["maxWidth"], params["maxHeight"])
|
|
377
|
+
await self.screencast.start(message["id"])
|
|
355
378
|
await self._simple_response(message, None)
|
|
356
379
|
|
|
357
380
|
async def _page_stop_screencast(self, message):
|
|
@@ -362,227 +385,242 @@ class CdpTarget:
|
|
|
362
385
|
|
|
363
386
|
async def _page_screencast_frame_ack(self, message):
|
|
364
387
|
if self.screencast is not None:
|
|
365
|
-
self.screencast.ack(message[
|
|
388
|
+
self.screencast.ack(message["params"]["sessionId"])
|
|
366
389
|
await self._simple_response(message, None)
|
|
367
390
|
|
|
368
391
|
async def _page_get_resource_tree(self, message):
|
|
369
|
-
result = await self.send_message_with_result(message[
|
|
370
|
-
self.frame = result[
|
|
392
|
+
result = await self.send_message_with_result(message["id"], message["method"], message["params"])
|
|
393
|
+
self.frame = result["result"]["frameTree"]["frame"]
|
|
371
394
|
await self.output_queue.put(result)
|
|
372
395
|
|
|
373
396
|
async def _emulation_set_emulated_media(self, message):
|
|
374
|
-
message[
|
|
397
|
+
message["method"] = "Page.setEmulatedMedia"
|
|
375
398
|
await self._send_message_to_target(message)
|
|
376
399
|
|
|
377
400
|
async def _emulation_set_auto_dark_mode_override(self, message):
|
|
378
|
-
message[
|
|
379
|
-
params = message[
|
|
401
|
+
message["method"] = "Page.setForcedAppearance"
|
|
402
|
+
params = message["params"]
|
|
380
403
|
if not params:
|
|
381
404
|
await self._simple_response(message, None)
|
|
382
405
|
return
|
|
383
|
-
message[
|
|
406
|
+
message["params"] = {"appearance": "Dark" if params["enabled"] else "Light"}
|
|
384
407
|
await self._send_message_to_target(message)
|
|
385
408
|
|
|
386
409
|
async def _debugger_set_blackbox_patterns(self, message):
|
|
387
|
-
for pattern in message[
|
|
388
|
-
await self.send_message_with_result(
|
|
389
|
-
|
|
410
|
+
for pattern in message["params"]["patterns"]:
|
|
411
|
+
await self.send_message_with_result(
|
|
412
|
+
message["id"], "Debugger.setShouldBlackboxURL", {"url": pattern, "shouldBlackbox": True}
|
|
413
|
+
)
|
|
390
414
|
await self._simple_response(message, None)
|
|
391
415
|
|
|
392
416
|
async def _debugger_set_breakpoint_by_url(self, message):
|
|
393
|
-
condition = message[
|
|
417
|
+
condition = message["params"].pop("condition", "")
|
|
394
418
|
if condition:
|
|
395
|
-
message[
|
|
419
|
+
message["params"]["options"]["condition"] = condition
|
|
396
420
|
await self._send_message_to_target(message)
|
|
397
421
|
|
|
398
422
|
async def _domdebugger_get_event_listeners(self, message):
|
|
399
|
-
node = {
|
|
400
|
-
listeners = await self.send_message_with_result(message[
|
|
401
|
-
if
|
|
423
|
+
node = {"nodeId": await self.object_id_to_node_id(message["params"]["objectId"], message["id"])}
|
|
424
|
+
listeners = await self.send_message_with_result(message["id"], "DOM.getEventListenersForNode", node)
|
|
425
|
+
if "error" in listeners:
|
|
402
426
|
await self._simple_response(message, None)
|
|
403
427
|
return
|
|
404
428
|
listeners_out = []
|
|
405
|
-
for listener in listeners[
|
|
429
|
+
for listener in listeners["result"]["listeners"]:
|
|
406
430
|
data = {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
431
|
+
"type": listener["type"],
|
|
432
|
+
"useCapture": listener["useCapture"],
|
|
433
|
+
"passive": listener.get("passive", False),
|
|
434
|
+
"once": listener.get("once", False),
|
|
411
435
|
}
|
|
412
|
-
if
|
|
413
|
-
data[
|
|
414
|
-
data[
|
|
415
|
-
data[
|
|
436
|
+
if "location" in listener:
|
|
437
|
+
data["scriptId"] = listener["location"]["scriptId"]
|
|
438
|
+
data["lineNumber"] = listener["location"]["lineNumber"]
|
|
439
|
+
data["columnNumber"] = listener["location"]["columnNumber"]
|
|
416
440
|
listeners_out.append(data)
|
|
417
|
-
await self.output_queue.put({
|
|
441
|
+
await self.output_queue.put({"id": message["id"], "result": {"listeners": listeners_out}})
|
|
418
442
|
|
|
419
443
|
async def _network_set_cache_disabled(self, message):
|
|
420
|
-
message[
|
|
421
|
-
message[
|
|
444
|
+
message["method"] = "Network.setResourceCachingDisabled"
|
|
445
|
+
message["params"] = {"disabled": message["params"]["cacheDisabled"]}
|
|
422
446
|
await self._send_message_to_target(message)
|
|
423
447
|
|
|
424
448
|
async def _network_load_network_resource(self, message):
|
|
425
|
-
await self.output_queue.put({
|
|
449
|
+
await self.output_queue.put({"id": message["id"], "result": {"resource": {"success": True}}})
|
|
426
450
|
|
|
427
451
|
async def _service_worker_enable(self, message):
|
|
428
|
-
message[
|
|
452
|
+
message["method"] = "Worker.enable"
|
|
429
453
|
await self._send_message_to_target(message)
|
|
430
454
|
|
|
431
455
|
async def _overlay_highlight_node(self, message):
|
|
432
|
-
message[
|
|
456
|
+
message["method"] = "DOM.highlightNode"
|
|
433
457
|
await self._send_message_to_target(message)
|
|
434
458
|
|
|
435
459
|
async def _runtime_compile_script(self, message):
|
|
436
|
-
self._script_source_to_context_id[message[
|
|
437
|
-
response = await self.send_message_with_result(
|
|
438
|
-
|
|
439
|
-
|
|
460
|
+
self._script_source_to_context_id[message["params"]["expression"]] = message["params"]["executionContextId"]
|
|
461
|
+
response = await self.send_message_with_result(
|
|
462
|
+
message["id"], "Runtime.parse", {"source": message["params"]["expression"]}
|
|
463
|
+
)
|
|
464
|
+
if response["result"]["result"] == "none":
|
|
440
465
|
await self._simple_response(message, None)
|
|
441
466
|
return
|
|
442
|
-
lines = message[
|
|
443
|
-
lines = lines if lines else [
|
|
444
|
-
await self.output_queue.put({
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
467
|
+
lines = message["params"]["expression"][: response["result"]["range"]["endOffset"]].splitlines()
|
|
468
|
+
lines = lines if lines else [""]
|
|
469
|
+
await self.output_queue.put({
|
|
470
|
+
"id": message["id"],
|
|
471
|
+
"result": {
|
|
472
|
+
"exceptionDetails": {
|
|
473
|
+
"exceptionId": 1,
|
|
474
|
+
"text": response["result"]["message"],
|
|
475
|
+
"lineNumber": len(lines) - 1,
|
|
476
|
+
"columnNumber": len(lines[-1]) - 1,
|
|
477
|
+
}
|
|
478
|
+
},
|
|
479
|
+
})
|
|
452
480
|
|
|
453
481
|
async def _runtime_get_isolate_id(self, message):
|
|
454
|
-
await self.output_queue.put({
|
|
482
|
+
await self.output_queue.put({"id": message["id"], "result": {"id": self._default_execution_id}})
|
|
455
483
|
|
|
456
484
|
async def _target_set_auto_attach(self, message):
|
|
457
485
|
await self._simple_response(message, None)
|
|
458
|
-
await self.output_queue.put({'method': 'Target.attachedToTarget', 'params': {
|
|
459
|
-
'sessionId': self.protocol.id_, 'targetInfo': {'targetId': self.target_id}, 'waitingForDebugger': True
|
|
460
|
-
}})
|
|
461
|
-
|
|
462
|
-
async def _css_take_computed_style_updates(self, message):
|
|
463
486
|
await self.output_queue.put({
|
|
464
|
-
|
|
465
|
-
|
|
487
|
+
"method": "Target.attachedToTarget",
|
|
488
|
+
"params": {
|
|
489
|
+
"sessionId": self.protocol.id_,
|
|
490
|
+
"targetInfo": {"targetId": self.target_id},
|
|
491
|
+
"waitingForDebugger": True,
|
|
492
|
+
},
|
|
466
493
|
})
|
|
467
494
|
|
|
495
|
+
async def _css_take_computed_style_updates(self, message):
|
|
496
|
+
await self.output_queue.put({"id": message["id"], "result": {"nodeIds": []}})
|
|
497
|
+
|
|
468
498
|
async def _css_add_rule(self, message):
|
|
469
|
-
message[
|
|
499
|
+
message["params"]["selector"] = message["params"]["ruleText"].split("{")[0]
|
|
470
500
|
await self._send_message_to_target(message)
|
|
471
501
|
|
|
472
502
|
async def _input_emulate_touch_from_mouse_event(self, message):
|
|
473
|
-
params = message[
|
|
474
|
-
if params[
|
|
475
|
-
delta_x, delta_y = params[
|
|
476
|
-
await self.evaluate_and_result(message[
|
|
477
|
-
elif params[
|
|
503
|
+
params = message["params"]
|
|
504
|
+
if params["type"] == "mouseWheel":
|
|
505
|
+
delta_x, delta_y = params["deltaX"] // self.screencast.scale, params["deltaY"] // self.screencast.scale
|
|
506
|
+
await self.evaluate_and_result(message["id"], f"window.scrollBy({-delta_x}, {-delta_y})")
|
|
507
|
+
elif params["type"] == "mouseReleased":
|
|
478
508
|
pass
|
|
479
509
|
else:
|
|
480
|
-
modifiers = params[
|
|
481
|
-
x, y = params[
|
|
510
|
+
modifiers = params["modifiers"]
|
|
511
|
+
x, y = params["x"] // self.screencast.scale, params["y"] // self.screencast.scale
|
|
482
512
|
event_params = {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
513
|
+
"screenX": x,
|
|
514
|
+
"screenY": y,
|
|
515
|
+
"clientX": 0,
|
|
516
|
+
"clientY": 0,
|
|
517
|
+
"altKey": bool(modifiers & 1),
|
|
518
|
+
"ctrlKey": bool(modifiers & 2),
|
|
519
|
+
"metaKey": bool(modifiers & 4),
|
|
520
|
+
"shiftKey": bool(modifiers & 8),
|
|
521
|
+
"button": params["button"],
|
|
522
|
+
"bubbles": True,
|
|
523
|
+
"cancelable": False,
|
|
486
524
|
}
|
|
487
|
-
type_ = {
|
|
525
|
+
type_ = {"mousePressed": "click", "mouseReleased": "click", "mouseMoved": "mousemove"}[params["type"]]
|
|
488
526
|
event_params = json.dumps(event_params)
|
|
489
527
|
simulate_mouse_event = (
|
|
490
|
-
|
|
491
|
-
f
|
|
492
|
-
f
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
528
|
+
"function simulateMouseEvent(type){"
|
|
529
|
+
f"const element = document.elementFromPoint({x}, {y});"
|
|
530
|
+
f"const e = new MouseEvent(type, JSON.parse('{event_params}'));"
|
|
531
|
+
"element.dispatchEvent(e);"
|
|
532
|
+
"element.focus();"
|
|
533
|
+
"return e;}"
|
|
496
534
|
)
|
|
497
|
-
await self.evaluate_and_result(message[
|
|
498
|
-
if type_ ==
|
|
499
|
-
await self.evaluate_and_result(message[
|
|
535
|
+
await self.evaluate_and_result(message["id"], f'({simulate_mouse_event})("{type_}")')
|
|
536
|
+
if type_ == "click":
|
|
537
|
+
await self.evaluate_and_result(message["id"], f'({simulate_mouse_event})("mouseup")')
|
|
500
538
|
|
|
501
539
|
await self._simple_response(message, None)
|
|
502
540
|
|
|
503
541
|
async def _input_dispatch_key_event(self, message):
|
|
504
|
-
params = message[
|
|
505
|
-
key = params[
|
|
506
|
-
if params[
|
|
507
|
-
manipulation =
|
|
508
|
-
elif params[
|
|
542
|
+
params = message["params"]
|
|
543
|
+
key = params["key"]
|
|
544
|
+
if params["type"] == "keyUp" and key == "Backspace":
|
|
545
|
+
manipulation = "document.activeElement.value = document.activeElement.value.slice(0, -1);"
|
|
546
|
+
elif params["type"] == "char" and key == "Enter":
|
|
509
547
|
manipulation = (
|
|
510
|
-
|
|
548
|
+
"var tagName = document.activeElement.tagName.toLowerCase();"
|
|
511
549
|
'if (tagName === "textarea" || document.activeElement.isContentEditable) {'
|
|
512
550
|
' document.activeElement.value = document.activeElement.value + "\\n";'
|
|
513
|
-
|
|
551
|
+
"} else {"
|
|
514
552
|
' const result = document.evaluate("./ancestor-or-self::form", document.activeElement, '
|
|
515
|
-
|
|
516
|
-
|
|
553
|
+
" null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);"
|
|
554
|
+
" const e = result.singleNodeValue.ownerDocument.createEvent('Event');"
|
|
517
555
|
' e.initEvent("submit", true, true);'
|
|
518
|
-
|
|
519
|
-
|
|
556
|
+
" if (result.singleNodeValue.dispatchEvent(e)) { result.singleNodeValue.submit() }"
|
|
557
|
+
"}"
|
|
520
558
|
)
|
|
521
|
-
elif params[
|
|
522
|
-
text = params[
|
|
559
|
+
elif params["type"] == "char":
|
|
560
|
+
text = params["text"]
|
|
523
561
|
manipulation = f'document.activeElement.value = document.activeElement.value + "{text}";'
|
|
524
562
|
else:
|
|
525
563
|
await self._simple_response(message, None)
|
|
526
564
|
return
|
|
527
565
|
|
|
528
566
|
simulate_key_event = (
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
567
|
+
"function isEditable(element) {"
|
|
568
|
+
" if (element.disabled || element.readOnly)"
|
|
569
|
+
" return false;"
|
|
570
|
+
" var tagName = element.tagName.toLowerCase();"
|
|
533
571
|
' if (tagName === "textarea" || element.isContentEditable)'
|
|
534
|
-
|
|
572
|
+
" return true;"
|
|
535
573
|
' if (tagName != "input")'
|
|
536
|
-
|
|
537
|
-
|
|
574
|
+
" return false;"
|
|
575
|
+
" switch (element.type) {"
|
|
538
576
|
' case "color": case "date": case "datetime-local": case "email": case "file": case "month": '
|
|
539
577
|
' case "number": case "password": case "range": case "search": case "tel": case "text": case "time": '
|
|
540
578
|
' case "url": case "week":'
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
f
|
|
547
|
-
|
|
579
|
+
" return true;"
|
|
580
|
+
" }"
|
|
581
|
+
" return false;"
|
|
582
|
+
"}"
|
|
583
|
+
"if (isEditable(document.activeElement)) {"
|
|
584
|
+
f"{manipulation}"
|
|
585
|
+
"}"
|
|
548
586
|
)
|
|
549
|
-
await self.evaluate_and_result(message[
|
|
587
|
+
await self.evaluate_and_result(message["id"], simulate_key_event)
|
|
550
588
|
await self._simple_response(message, None)
|
|
551
589
|
|
|
552
590
|
async def _target_created(self, message):
|
|
553
|
-
self.target_id = message[
|
|
554
|
-
message[
|
|
555
|
-
message[
|
|
556
|
-
message[
|
|
557
|
-
message[
|
|
591
|
+
self.target_id = message["params"]["targetInfo"]["targetId"]
|
|
592
|
+
message["method"] = "Target.targetInfoChanged"
|
|
593
|
+
message["params"]["targetInfo"]["url"] = await self.evaluate_and_result(1, "window.location.href")
|
|
594
|
+
message["params"]["targetInfo"]["title"] = await self.evaluate_and_result(1, "document.title")
|
|
595
|
+
message["params"]["targetInfo"]["attached"] = message["params"]["targetInfo"].pop("isProvisional")
|
|
558
596
|
await self.output_queue.put(message)
|
|
559
597
|
|
|
560
598
|
async def _target_destroyed(self, message):
|
|
561
|
-
result = await self.send_message_with_result(1,
|
|
562
|
-
self.frame = result[
|
|
599
|
+
result = await self.send_message_with_result(1, "Page.getResourceTree", {})
|
|
600
|
+
self.frame = result["result"]["frameTree"]["frame"]
|
|
563
601
|
await self.output_queue.put({
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
}
|
|
602
|
+
"method": "Page.frameNavigated",
|
|
603
|
+
"params": {
|
|
604
|
+
"frame": self.frame,
|
|
605
|
+
},
|
|
568
606
|
})
|
|
569
607
|
await self.output_queue.put({
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
}
|
|
608
|
+
"method": "Page.loadEventFired",
|
|
609
|
+
"params": {
|
|
610
|
+
"timestamp": datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f"),
|
|
611
|
+
},
|
|
574
612
|
})
|
|
575
|
-
await self.output_queue.put({
|
|
613
|
+
await self.output_queue.put({"method": "DOM.documentUpdated"})
|
|
576
614
|
|
|
577
615
|
async def _target_dispatch_message_from_target(self, message):
|
|
578
|
-
message = json.loads(message[
|
|
579
|
-
if
|
|
616
|
+
message = json.loads(message["params"]["message"])
|
|
617
|
+
if "error" in message:
|
|
580
618
|
logger.error(message)
|
|
581
|
-
if message.get(
|
|
582
|
-
await self.to_cdp_special_dispatched_messages_methods[message[
|
|
619
|
+
if message.get("method", "") in self.to_cdp_special_dispatched_messages_methods:
|
|
620
|
+
await self.to_cdp_special_dispatched_messages_methods[message["method"]](message)
|
|
583
621
|
else:
|
|
584
|
-
if
|
|
585
|
-
logger.debug(
|
|
622
|
+
if "method" in message:
|
|
623
|
+
logger.debug("DISPACHING", message["method"])
|
|
586
624
|
await self.output_queue.put(message)
|
|
587
625
|
|
|
588
626
|
async def _target_did_commit_provisional_target(self, message):
|
|
@@ -593,88 +631,88 @@ class CdpTarget:
|
|
|
593
631
|
await self.output_queue.put(message)
|
|
594
632
|
|
|
595
633
|
async def _debugger_script_failed_to_parse(self, message):
|
|
596
|
-
message[
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
634
|
+
message["params"] = {
|
|
635
|
+
"endColumn": 0,
|
|
636
|
+
"endLine": message["params"]["errorLine"],
|
|
637
|
+
"executionContextId": self._script_source_to_context_id[message["params"]["scriptSource"]],
|
|
638
|
+
"startColumn": 0,
|
|
639
|
+
"startLine": message["params"]["startLine"],
|
|
640
|
+
"url": message["params"]["url"],
|
|
641
|
+
"scriptId": self._script_source_to_context_id[message["params"]["scriptSource"]],
|
|
642
|
+
"hash": hashlib.sha1(message["params"]["scriptSource"]).hexdigest(),
|
|
605
643
|
}
|
|
606
644
|
await self.output_queue.put(message)
|
|
607
645
|
|
|
608
646
|
async def _debugger_paused(self, message):
|
|
609
|
-
message[
|
|
610
|
-
if
|
|
611
|
-
message[
|
|
647
|
+
message["params"]["reason"] = DEBUGGER_PAUSED_REASON[message["params"]["reason"]]
|
|
648
|
+
if "breakpointId" in message["params"].get("data", {}):
|
|
649
|
+
message["params"]["hitBreakpoints"] = [message["params"]["data"]["breakpointId"]]
|
|
612
650
|
await self.output_queue.put(message)
|
|
613
651
|
|
|
614
652
|
async def _debugger_global_object_cleared(self, message):
|
|
615
|
-
await self.output_queue.put({
|
|
653
|
+
await self.output_queue.put({"method": "DOM.documentUpdated"})
|
|
616
654
|
|
|
617
655
|
async def _page_default_appearance_did_change(self, message):
|
|
618
656
|
pass
|
|
619
657
|
|
|
620
658
|
async def _runtime_execution_context_created(self, message):
|
|
621
|
-
if message[
|
|
622
|
-
self._default_execution_id = message[
|
|
623
|
-
message[
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
659
|
+
if message["params"]["context"]["type"] == "normal":
|
|
660
|
+
self._default_execution_id = message["params"]["context"]["id"]
|
|
661
|
+
message["params"] = {
|
|
662
|
+
"context": {
|
|
663
|
+
"id": message["params"]["context"]["id"],
|
|
664
|
+
"origin": "default",
|
|
665
|
+
"name": "",
|
|
666
|
+
"uniqueId": message["params"]["context"]["frameId"],
|
|
629
667
|
}
|
|
630
668
|
}
|
|
631
669
|
await self.output_queue.put(message)
|
|
632
670
|
|
|
633
671
|
async def _console_message_added(self, message):
|
|
634
672
|
log_record = {
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
673
|
+
"source": LOG_MESSAGE_SOURCES[message["params"]["message"]["source"]],
|
|
674
|
+
"level": LOG_MESSAGE_LEVELS[message["params"]["message"]["level"]],
|
|
675
|
+
"text": message["params"]["message"]["text"],
|
|
676
|
+
"timestamp": datetime.now().timestamp(),
|
|
639
677
|
}
|
|
640
|
-
if
|
|
641
|
-
log_record[
|
|
642
|
-
if
|
|
643
|
-
log_record[
|
|
644
|
-
if
|
|
645
|
-
log_record[
|
|
678
|
+
if "url" in message["params"]["message"]:
|
|
679
|
+
log_record["url"] = message["params"]["message"]["url"]
|
|
680
|
+
if "line" in message["params"]["message"]:
|
|
681
|
+
log_record["lineNumber"] = message["params"]["message"]["line"]
|
|
682
|
+
if "networkRequestId" in message["params"]["message"]:
|
|
683
|
+
log_record["networkRequestId"] = message["params"]["message"]["networkRequestId"]
|
|
646
684
|
|
|
647
|
-
await self.output_queue.put({
|
|
685
|
+
await self.output_queue.put({"method": "Log.entryAdded", "params": {"entry": log_record}})
|
|
648
686
|
|
|
649
687
|
async def _network_response_received(self, message):
|
|
650
|
-
params = message[
|
|
651
|
-
message[
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
688
|
+
params = message["params"]
|
|
689
|
+
message["params"] = {
|
|
690
|
+
"loaderId": params["loaderId"],
|
|
691
|
+
"requestId": params["requestId"],
|
|
692
|
+
"timestamp": params["timestamp"],
|
|
693
|
+
"type": params["type"] if params["type"] in NETWORK_RESOURCE_TYPES else "Other",
|
|
694
|
+
"response": {
|
|
695
|
+
"url": params["response"]["url"],
|
|
696
|
+
"status": params["response"]["status"],
|
|
697
|
+
"statusText": params["response"]["statusText"],
|
|
698
|
+
"headers": params["response"]["headers"],
|
|
699
|
+
"mimeType": params["response"]["mimeType"],
|
|
700
|
+
"connectionReused": False,
|
|
701
|
+
"encodedDataLength": 0,
|
|
702
|
+
"securityState": "unknown",
|
|
665
703
|
},
|
|
666
704
|
}
|
|
667
|
-
if
|
|
668
|
-
message[
|
|
705
|
+
if "frameId" in params:
|
|
706
|
+
message["params"]["frameId"] = params["frameId"]
|
|
669
707
|
await self.output_queue.put(message)
|
|
670
708
|
|
|
671
709
|
async def _network_loading_finished(self, message):
|
|
672
|
-
params = message[
|
|
673
|
-
header_size = params[
|
|
674
|
-
body_size = params[
|
|
675
|
-
message[
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
710
|
+
params = message["params"]
|
|
711
|
+
header_size = params["metrics"].get("responseHeaderBytesReceived", 0)
|
|
712
|
+
body_size = params["metrics"].get("responseBodyBytesReceived", 0)
|
|
713
|
+
message["params"] = {
|
|
714
|
+
"encodedDataLength": header_size + body_size,
|
|
715
|
+
"requestId": params["requestId"],
|
|
716
|
+
"timestamp": params["timestamp"],
|
|
679
717
|
}
|
|
680
718
|
await self.output_queue.put(message)
|