forked from llimllib/chrome-control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Target.py
140 lines (82 loc) · 3.9 KB
/
Target.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
139
from enum import Enum
from typing import Any, List
from base import ChromeCommand
TargetID = str
BrowserContextID = str
class TargetInfo:
def __init__(self, targetId: "TargetID", type: str, title: str, url: str):
self.targetId = targetId
self.type = type
self.title = title
self.url = url
class RemoteLocation:
def __init__(self, host: str, port: int):
self.host = host
self.port = port
class setDiscoverTargets(ChromeCommand):
"""Controls whether to discover available targets and notify via <code>targetCreated/targetDestroyed</code> events."""
def __init__(self, discover: bool):
# Whether to discover available targets.
self.discover = discover
class setAutoAttach(ChromeCommand):
"""Controls whether to automatically attach to new targets which are considered to be related to this one. When turned on, attaches to all existing related targets as well. When turned off, automatically detaches from all currently attached targets."""
def __init__(self, autoAttach: bool, waitForDebuggerOnStart: bool):
# Whether to auto-attach to related targets.
self.autoAttach = autoAttach
# Whether to pause new targets when attaching to them. Use <code>Runtime.runIfWaitingForDebugger</code> to run paused targets.
self.waitForDebuggerOnStart = waitForDebuggerOnStart
class setAttachToFrames(ChromeCommand):
def __init__(self, value: bool):
# Whether to attach to frames.
self.value = value
class setRemoteLocations(ChromeCommand):
"""Enables target discovery for the specified locations, when <code>setDiscoverTargets</code> was set to <code>true</code>."""
def __init__(self, locations: List):
# List of remote locations.
self.locations = locations
class sendMessageToTarget(ChromeCommand):
"""Sends protocol message to the target with given id."""
def __init__(self, targetId: str, message: str):
self.targetId = targetId
self.message = message
class getTargetInfo(ChromeCommand):
"""Returns information about a target."""
def __init__(self, targetId: "TargetID"):
self.targetId = targetId
class activateTarget(ChromeCommand):
"""Activates (focuses) the target."""
def __init__(self, targetId: "TargetID"):
self.targetId = targetId
class closeTarget(ChromeCommand):
"""Closes the target. If the target is a page that gets closed too."""
def __init__(self, targetId: "TargetID"):
self.targetId = targetId
class attachToTarget(ChromeCommand):
"""Attaches to the target with given id."""
def __init__(self, targetId: "TargetID"):
self.targetId = targetId
class detachFromTarget(ChromeCommand):
"""Detaches from the target with given id."""
def __init__(self, targetId: "TargetID"):
self.targetId = targetId
class createBrowserContext(ChromeCommand):
"""Creates a new empty BrowserContext. Similar to an incognito profile but you can have more than one."""
def __init__(self): pass
class disposeBrowserContext(ChromeCommand):
"""Deletes a BrowserContext, will fail of any open page uses it."""
def __init__(self, browserContextId: "BrowserContextID"):
self.browserContextId = browserContextId
class createTarget(ChromeCommand):
"""Creates a new page."""
def __init__(self, url: str, width: int=None, height: int=None, browserContextId: "BrowserContextID"=None):
# The initial URL the page will be navigated to.
self.url = url
# Frame width in DIP (headless chrome only).
self.width = width
# Frame height in DIP (headless chrome only).
self.height = height
# The browser context to create the page in (headless chrome only).
self.browserContextId = browserContextId
class getTargets(ChromeCommand):
"""Retrieves a list of available targets."""
def __init__(self): pass