target
AttachedToTarget
dataclass
EXPERIMENTAL
Issued when attached to target because of auto-attach or attachToTarget
command.
Source code in zendriver/cdp/target.py
session_id: SessionID
instance-attribute
target_info: TargetInfo
instance-attribute
waiting_for_debugger: bool
instance-attribute
__init__(session_id, target_info, waiting_for_debugger)
from_json(json)
classmethod
Source code in zendriver/cdp/target.py
DetachedFromTarget
dataclass
EXPERIMENTAL
Issued when detached from target for any reason (including detachFromTarget
command). Can be
issued multiple times per target if multiple sessions have been attached to it.
Source code in zendriver/cdp/target.py
session_id: SessionID
instance-attribute
target_id: typing.Optional[TargetID]
instance-attribute
__init__(session_id, target_id)
from_json(json)
classmethod
Source code in zendriver/cdp/target.py
FilterEntry
dataclass
A filter used by target query/discovery/auto-attach operations.
Source code in zendriver/cdp/target.py
exclude: typing.Optional[bool] = None
class-attribute
instance-attribute
type_: typing.Optional[str] = None
class-attribute
instance-attribute
__init__(exclude=None, type_=None)
from_json(json)
classmethod
Source code in zendriver/cdp/target.py
ReceivedMessageFromTarget
dataclass
Notifies about a new protocol message received from the session (as reported in
attachedToTarget
event).
Source code in zendriver/cdp/target.py
message: str
instance-attribute
session_id: SessionID
instance-attribute
target_id: typing.Optional[TargetID]
instance-attribute
__init__(session_id, message, target_id)
from_json(json)
classmethod
Source code in zendriver/cdp/target.py
RemoteLocation
dataclass
Source code in zendriver/cdp/target.py
host: str
instance-attribute
port: int
instance-attribute
__init__(host, port)
from_json(json)
classmethod
SessionID
Bases: str
Unique identifier of attached debugging session.
Source code in zendriver/cdp/target.py
__repr__()
from_json(json)
classmethod
TargetCrashed
dataclass
Issued when a target has crashed.
Source code in zendriver/cdp/target.py
error_code: int
instance-attribute
status: str
instance-attribute
target_id: TargetID
instance-attribute
__init__(target_id, status, error_code)
TargetCreated
dataclass
Issued when a possible inspection target is created.
Source code in zendriver/cdp/target.py
TargetDestroyed
dataclass
Issued when a target is destroyed.
Source code in zendriver/cdp/target.py
TargetFilter
Bases: list
The entries in TargetFilter are matched sequentially against targets and
the first entry that matches determines if the target is included or not,
depending on the value of exclude
field in the entry.
If filter is not specified, the one assumed is
[{type: "browser", exclude: true}, {type: "tab", exclude: true}, {}]
(i.e. include everything but browser
and tab
).
Source code in zendriver/cdp/target.py
__repr__()
from_json(json)
classmethod
TargetID
Bases: str
Source code in zendriver/cdp/target.py
__repr__()
from_json(json)
classmethod
TargetInfo
dataclass
Source code in zendriver/cdp/target.py
attached: bool
instance-attribute
browser_context_id: typing.Optional[browser.BrowserContextID] = None
class-attribute
instance-attribute
can_access_opener: bool
instance-attribute
opener_frame_id: typing.Optional[page.FrameId] = None
class-attribute
instance-attribute
opener_id: typing.Optional[TargetID] = None
class-attribute
instance-attribute
subtype: typing.Optional[str] = None
class-attribute
instance-attribute
target_id: TargetID
instance-attribute
title: str
instance-attribute
type_: str
instance-attribute
url: str
instance-attribute
__init__(target_id, type_, title, url, attached, can_access_opener, opener_id=None, opener_frame_id=None, browser_context_id=None, subtype=None)
from_json(json)
classmethod
Source code in zendriver/cdp/target.py
to_json()
Source code in zendriver/cdp/target.py
TargetInfoChanged
dataclass
Issued when some information about a target has changed. This only happens between
targetCreated
and targetDestroyed
.
Source code in zendriver/cdp/target.py
activate_target(target_id)
Activates (focuses) the target.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_id
|
TargetID
|
|
required |
Source code in zendriver/cdp/target.py
attach_to_browser_target()
Attaches to the browser target, only uses flat sessionId mode.
EXPERIMENTAL
Returns:
Type | Description |
---|---|
Generator[T_JSON_DICT, T_JSON_DICT, SessionID]
|
Id assigned to the session. |
Source code in zendriver/cdp/target.py
attach_to_target(target_id, flatten=None)
Attaches to the target with given id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_id
|
TargetID
|
|
required |
flatten
|
Optional[bool]
|
(Optional) Enables "flat" access to the session via specifying sessionId attribute in the commands. We plan to make this the default, deprecate non-flattened mode, and eventually retire it. See crbug.com/991325. |
None
|
Returns:
Type | Description |
---|---|
Generator[T_JSON_DICT, T_JSON_DICT, SessionID]
|
Id assigned to the session. |
Source code in zendriver/cdp/target.py
auto_attach_related(target_id, wait_for_debugger_on_start, filter_=None)
Adds the specified target to the list of targets that will be monitored for any related target
creation (such as child frames, child workers and new versions of service worker) and reported
through attachedToTarget
. The specified target is also auto-attached.
This cancels the effect of any previous setAutoAttach
and is also cancelled by subsequent
setAutoAttach
. Only available at the Browser target.
EXPERIMENTAL
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_id
|
TargetID
|
|
required |
wait_for_debugger_on_start
|
bool
|
Whether to pause new targets when attaching to them. Use |
required |
filter_
|
Optional[TargetFilter]
|
(EXPERIMENTAL) (Optional) Only targets matching filter will be attached. |
None
|
Source code in zendriver/cdp/target.py
close_target(target_id)
Closes the target. If the target is a page that gets closed too.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_id
|
TargetID
|
|
required |
Returns:
Type | Description |
---|---|
Generator[T_JSON_DICT, T_JSON_DICT, bool]
|
Always set to true. If an error occurs, the response indicates protocol error. |
Source code in zendriver/cdp/target.py
create_browser_context(dispose_on_detach=None, proxy_server=None, proxy_bypass_list=None, origins_with_universal_network_access=None)
Creates a new empty BrowserContext. Similar to an incognito profile but you can have more than one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dispose_on_detach
|
Optional[bool]
|
(EXPERIMENTAL) (Optional) If specified, disposes this context when debugging session disconnects. |
None
|
proxy_server
|
Optional[str]
|
(EXPERIMENTAL) (Optional) Proxy server, similar to the one passed to --proxy-server |
None
|
proxy_bypass_list
|
Optional[str]
|
(EXPERIMENTAL) (Optional) Proxy bypass list, similar to the one passed to --proxy-bypass-list |
None
|
origins_with_universal_network_access
|
Optional[List[str]]
|
(EXPERIMENTAL) (Optional) An optional list of origins to grant unlimited cross-origin access to. Parts of the URL other than those constituting origin are ignored. |
None
|
Returns:
Type | Description |
---|---|
Generator[T_JSON_DICT, T_JSON_DICT, BrowserContextID]
|
The id of the context created. |
Source code in zendriver/cdp/target.py
create_target(url, width=None, height=None, browser_context_id=None, enable_begin_frame_control=None, new_window=None, background=None, for_tab=None)
Creates a new page.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
The initial URL the page will be navigated to. An empty string indicates about:blank. |
required |
width
|
Optional[int]
|
(Optional) Frame width in DIP (headless chrome only). |
None
|
height
|
Optional[int]
|
(Optional) Frame height in DIP (headless chrome only). |
None
|
browser_context_id
|
Optional[BrowserContextID]
|
(EXPERIMENTAL) (Optional) The browser context to create the page in. |
None
|
enable_begin_frame_control
|
Optional[bool]
|
(EXPERIMENTAL) (Optional) Whether BeginFrames for this target will be controlled via DevTools (headless chrome only, not supported on MacOS yet, false by default). |
None
|
new_window
|
Optional[bool]
|
(Optional) Whether to create a new Window or Tab (chrome-only, false by default). |
None
|
background
|
Optional[bool]
|
(Optional) Whether to create the target in background or foreground (chrome-only, false by default). |
None
|
for_tab
|
Optional[bool]
|
(EXPERIMENTAL) (Optional) Whether to create the target of type "tab". |
None
|
Returns:
Type | Description |
---|---|
Generator[T_JSON_DICT, T_JSON_DICT, TargetID]
|
The id of the page opened. |
Source code in zendriver/cdp/target.py
detach_from_target(session_id=None, target_id=None)
Detaches session with given id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session_id
|
Optional[SessionID]
|
(Optional) Session to detach. |
None
|
target_id
|
Optional[TargetID]
|
(DEPRECATED) (Optional) Deprecated. |
None
|
Source code in zendriver/cdp/target.py
dispose_browser_context(browser_context_id)
Deletes a BrowserContext. All the belonging pages will be closed without calling their beforeunload hooks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
browser_context_id
|
BrowserContextID
|
|
required |
Source code in zendriver/cdp/target.py
expose_dev_tools_protocol(target_id, binding_name=None)
Inject object to the target's main frame that provides a communication channel with browser target.
Injected object will be available as window[bindingName]
.
The object has the following API:
- binding.send(json)
- a method to send messages over the remote debugging protocol
- binding.onmessage = json => handleMessage(json)
- a callback that will be called for the protocol notifications and command responses.
EXPERIMENTAL
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_id
|
TargetID
|
|
required |
binding_name
|
Optional[str]
|
(Optional) Binding name, 'cdp' if not specified. |
None
|
Source code in zendriver/cdp/target.py
get_browser_contexts()
Returns all browser contexts created with Target.createBrowserContext
method.
Returns:
Type | Description |
---|---|
Generator[T_JSON_DICT, T_JSON_DICT, List[BrowserContextID]]
|
An array of browser context ids. |
Source code in zendriver/cdp/target.py
get_target_info(target_id=None)
Returns information about a target.
EXPERIMENTAL
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_id
|
Optional[TargetID]
|
(Optional) |
None
|
Returns:
Type | Description |
---|---|
Generator[T_JSON_DICT, T_JSON_DICT, TargetInfo]
|
|
Source code in zendriver/cdp/target.py
get_targets(filter_=None)
Retrieves a list of available targets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter_
|
Optional[TargetFilter]
|
(EXPERIMENTAL) (Optional) Only targets matching filter will be reported. If filter is not specified and target discovery is currently enabled, a filter used for target discovery is used for consistency. |
None
|
Returns:
Type | Description |
---|---|
Generator[T_JSON_DICT, T_JSON_DICT, List[TargetInfo]]
|
The list of targets. |
Source code in zendriver/cdp/target.py
send_message_to_target(message, session_id=None, target_id=None)
Sends protocol message over session with given id. Consider using flat mode instead; see commands attachToTarget, setAutoAttach, and crbug.com/991325.
.. deprecated:: 1.3
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str
|
|
required |
session_id
|
Optional[SessionID]
|
(Optional) Identifier of the session. |
None
|
target_id
|
Optional[TargetID]
|
(DEPRECATED) (Optional) Deprecated. |
None
|
Source code in zendriver/cdp/target.py
set_auto_attach(auto_attach, wait_for_debugger_on_start, flatten=None, filter_=None)
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.
This also clears all targets added by autoAttachRelated
from the list of targets to watch
for creation of related targets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
auto_attach
|
bool
|
Whether to auto-attach to related targets. |
required |
wait_for_debugger_on_start
|
bool
|
Whether to pause new targets when attaching to them. Use |
required |
flatten
|
Optional[bool]
|
(EXPERIMENTAL) (Optional) Enables "flat" access to the session via specifying sessionId attribute in the commands. We plan to make this the default, deprecate non-flattened mode, and eventually retire it. See crbug.com/991325. |
None
|
filter_
|
Optional[TargetFilter]
|
(EXPERIMENTAL) (Optional) Only targets matching filter will be attached. |
None
|
Source code in zendriver/cdp/target.py
set_discover_targets(discover, filter_=None)
Controls whether to discover available targets and notify via
targetCreated/targetInfoChanged/targetDestroyed
events.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
discover
|
bool
|
Whether to discover available targets. |
required |
filter_
|
Optional[TargetFilter]
|
(EXPERIMENTAL) (Optional) Only targets matching filter will be attached. If |
None
|
Source code in zendriver/cdp/target.py
set_remote_locations(locations)
Enables target discovery for the specified locations, when setDiscoverTargets
was set to
true
.
EXPERIMENTAL
Parameters:
Name | Type | Description | Default |
---|---|---|---|
locations
|
List[RemoteLocation]
|
List of remote locations. |
required |