connection
GLOBAL_DELAY = 0.005
module-attribute
MAX_SIZE: int = 2 ** 28
module-attribute
PING_TIMEOUT: int = 900
module-attribute
T = TypeVar('T')
module-attribute
TargetType = Union[cdp.target.TargetInfo, cdp.target.TargetID]
module-attribute
logger = logging.getLogger('uc.connection')
module-attribute
CantTouchThis
Bases: type
Source code in zendriver/core/connection.py
__setattr__(attr, value)
:meta private:
Source code in zendriver/core/connection.py
Connection
Source code in zendriver/core/connection.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 | |
__count__ = itertools.count(0)
instance-attribute
attached: bool | None
property
returns True if the current target is attached, False otherwise. if no target is set, it will return None.
browser_context_id: cdp.browser.BrowserContextID | None
property
returns the browser context id of the current target. if no target is set, it will return None.
can_access_opener: bool | None
property
returns True if the current target can access its opener, False otherwise. if no target is set, it will return None.
closed: bool
property
enabled_domains: list[Any] = []
instance-attribute
handlers: dict[Any, list[Union[Callable, Awaitable]]] = collections.defaultdict(list)
instance-attribute
listener: Listener | None = None
instance-attribute
mapper: dict[int, Transaction] = {}
instance-attribute
opener_frame_id: cdp.page.FrameId | None
property
returns the opener frame id of the current target. if no target is set, it will return None.
opener_id: cdp.target.TargetID | None
property
returns the opener id of the current target. if no target is set, it will return None.
recv_task = None
instance-attribute
subtype: str | None
property
returns the subtype of the current target. if no target is set, it will return None.
target: cdp.target.TargetInfo | None
property
writable
target_id: cdp.target.TargetID | None
property
returns the target id of the current target. if no target is set, it will return None.
title: str | None
property
returns the title of the current target. if no target is set, it will return None.
type_: str | None
property
returns the type of the current target. if no target is set, it will return None.
url: str | None
property
returns the url of the current target. if no target is set, it will return None.
websocket: websockets.asyncio.client.ClientConnection | None = None
class-attribute
instance-attribute
websocket_url: str = websocket_url
instance-attribute
__aenter__()
async
__aexit__(exc_type, exc_val, exc_tb)
async
__await__()
updates targets and wait for event listener to report idle. idle is reported when no new events are received for the duration of 1 second
Returns:
| Type | Description |
|---|---|
|
|
__init__(websocket_url, target=None, _owner=None, **kwargs)
Source code in zendriver/core/connection.py
aclose()
async
closes the websocket connection. should not be called manually by users.
Source code in zendriver/core/connection.py
add_handler(event_type_or_domain, handler)
add a handler for given event
if event_type_or_domain is a module instead of a type, it will find all available events and add the handler.
if you want to receive event updates (network traffic are also 'events') you can add handlers for those events. handlers can be regular callback functions or async coroutine functions (and also just lamba's). for example, you want to check the network traffic:
.. code-block::
page.add_handler(cdp.network.RequestWillBeSent, lambda event: print('network event => %s' % event.request))
the next time you make network traffic you will see your console print like crazy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_type_or_domain
|
Union[type, ModuleType]
|
|
required |
handler
|
Union[Callable, Awaitable]
|
|
required |
Returns:
| Type | Description |
|---|---|
|
|
Source code in zendriver/core/connection.py
aopen()
async
opens the websocket connection. should not be called manually by users
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in zendriver/core/connection.py
feed_cdp(cdp_obj)
used in specific cases, mostly during cdp.fetch.RequestPaused events, in which the browser literally blocks. using feed_cdp you can issue a response without a blocking "await".
note: this method won't cause a response. note: this is not an async method, just a regular method!
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cdp_obj
|
Generator[dict[str, Any], dict[str, Any], T]
|
|
required |
Returns:
| Type | Description |
|---|---|
|
|
Source code in zendriver/core/connection.py
remove_handlers(event_type=None, handler=None)
remove handlers for given event
if no event is provided, all handlers will be removed. if no handler is provided, all handlers for the event will be removed.
.. code-block::
# remove all handlers for all events
page.remove_handlers()
# remove all handlers for a specific event
page.remove_handlers(cdp.network.RequestWillBeSent)
# remove a specific handler for a specific event
page.remove_handlers(cdp.network.RequestWillBeSent, handler)
Source code in zendriver/core/connection.py
send(cdp_obj, _is_update=False)
async
send a protocol command. the commands are made using any of the cdp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cdp_obj
|
Generator[dict[str, Any], dict[str, Any], T]
|
the generator object created by a cdp method |
required |
_is_update
|
bool
|
internal flag prevents infinite loop by skipping the registeration of handlers when multiple calls to connection.send() are made |
False
|
Returns:
| Type | Description |
|---|---|
T
|
|
Source code in zendriver/core/connection.py
sleep(t=0.25)
async
update_target()
async
wait(t=None)
async
waits until the event listener reports idle (no new events received in certain timespan).
when t is provided, ensures waiting for t seconds, no matter what.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
int | float | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
|
|
Source code in zendriver/core/connection.py
EventTransaction
Bases: Transaction
Source code in zendriver/core/connection.py
event = self.result()
class-attribute
instance-attribute
value = self.result()
class-attribute
instance-attribute
__init__(event_object)
__repr__()
Source code in zendriver/core/connection.py
Listener
Source code in zendriver/core/connection.py
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 | |
connection = connection
instance-attribute
history: collections.deque[Any] = collections.deque()
instance-attribute
idle = asyncio.Event()
instance-attribute
max_history = 1000
instance-attribute
running: bool
property
task: asyncio.Future[None] | None = None
instance-attribute
time_before_considered_idle: float
property
writable
__init__(connection)
Source code in zendriver/core/connection.py
__repr__()
Source code in zendriver/core/connection.py
cancel()
listener_loop()
async
Source code in zendriver/core/connection.py
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 | |
ProtocolException
Bases: Exception
Source code in zendriver/core/connection.py
args = args
instance-attribute
code = None
instance-attribute
message = None
instance-attribute
__init__(*args)
Source code in zendriver/core/connection.py
SettingClassVarNotAllowedException
Transaction
Bases: Future[Any]
Source code in zendriver/core/connection.py
__cdp_obj__ = cdp_obj
instance-attribute
connection: Connection | None = None
instance-attribute
has_exception: bool
property
id: int | None = None
instance-attribute
message: str
property
params = params
instance-attribute
__call__(**response)
parsed the response message and marks the future complete
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
dict[str, Any]
|
|
{}
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in zendriver/core/connection.py
__init__(cdp_obj)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cdp_obj
|
Generator[dict[str, Any], dict[str, Any], Any]
|
|
required |