203 lines
6.3 KiB
Python
203 lines
6.3 KiB
Python
|
"""
|
||
|
This type stub file was generated by pyright.
|
||
|
"""
|
||
|
|
||
|
from subprocess import Popen
|
||
|
from typing import Any, Awaitable, Callable, Dict, List, Optional
|
||
|
from pyee import EventEmitter
|
||
|
from pyppeteer.connection import Connection
|
||
|
from pyppeteer.page import Page
|
||
|
from pyppeteer.target import Target
|
||
|
|
||
|
"""Browser module."""
|
||
|
logger = ...
|
||
|
class Browser(EventEmitter):
|
||
|
"""Browser class.
|
||
|
|
||
|
A Browser object is created when pyppeteer connects to chrome, either
|
||
|
through :func:`~pyppeteer.launcher.launch` or
|
||
|
:func:`~pyppeteer.launcher.connect`.
|
||
|
"""
|
||
|
Events = ...
|
||
|
def __init__(self, connection: Connection, contextIds: List[str], ignoreHTTPSErrors: bool, defaultViewport: Optional[Dict], process: Optional[Popen] = ..., closeCallback: Callable[[], Awaitable[None]] = ..., **kwargs: Any) -> None:
|
||
|
...
|
||
|
|
||
|
@property
|
||
|
def process(self) -> Optional[Popen]:
|
||
|
"""Return process of this browser.
|
||
|
|
||
|
If browser instance is created by :func:`pyppeteer.launcher.connect`,
|
||
|
return ``None``.
|
||
|
"""
|
||
|
...
|
||
|
|
||
|
async def createIncogniteBrowserContext(self) -> BrowserContext:
|
||
|
"""[Deprecated] Miss spelled method.
|
||
|
|
||
|
Use :meth:`createIncognitoBrowserContext` method instead.
|
||
|
"""
|
||
|
...
|
||
|
|
||
|
async def createIncognitoBrowserContext(self) -> BrowserContext:
|
||
|
"""Create a new incognito browser context.
|
||
|
|
||
|
This won't share cookies/cache with other browser contexts.
|
||
|
|
||
|
.. code::
|
||
|
|
||
|
browser = await launch()
|
||
|
# Create a new incognito browser context.
|
||
|
context = await browser.createIncognitoBrowserContext()
|
||
|
# Create a new page in a pristine context.
|
||
|
page = await context.newPage()
|
||
|
# Do stuff
|
||
|
await page.goto('https://example.com')
|
||
|
...
|
||
|
"""
|
||
|
...
|
||
|
|
||
|
@property
|
||
|
def browserContexts(self) -> List[BrowserContext]:
|
||
|
"""Return a list of all open browser contexts.
|
||
|
|
||
|
In a newly created browser, this will return a single instance of
|
||
|
``[BrowserContext]``
|
||
|
"""
|
||
|
...
|
||
|
|
||
|
@staticmethod
|
||
|
async def create(connection: Connection, contextIds: List[str], ignoreHTTPSErrors: bool, defaultViewport: Optional[Dict], process: Optional[Popen] = ..., closeCallback: Callable[[], Awaitable[None]] = ..., **kwargs: Any) -> Browser:
|
||
|
"""Create browser object."""
|
||
|
...
|
||
|
|
||
|
@property
|
||
|
def wsEndpoint(self) -> str:
|
||
|
"""Return websocket end point url."""
|
||
|
...
|
||
|
|
||
|
async def newPage(self) -> Page:
|
||
|
"""Make new page on this browser and return its object."""
|
||
|
...
|
||
|
|
||
|
def targets(self) -> List[Target]:
|
||
|
"""Get a list of all active targets inside the browser.
|
||
|
|
||
|
In case of multiple browser contexts, the method will return a list
|
||
|
with all the targets in all browser contexts.
|
||
|
"""
|
||
|
...
|
||
|
|
||
|
async def pages(self) -> List[Page]:
|
||
|
"""Get all pages of this browser.
|
||
|
|
||
|
Non visible pages, such as ``"background_page"``, will not be listed
|
||
|
here. You can find then using :meth:`pyppeteer.target.Target.page`.
|
||
|
|
||
|
In case of multiple browser contexts, this method will return a list
|
||
|
with all the pages in all browser contexts.
|
||
|
"""
|
||
|
...
|
||
|
|
||
|
async def version(self) -> str:
|
||
|
"""Get version of the browser."""
|
||
|
...
|
||
|
|
||
|
async def userAgent(self) -> str:
|
||
|
"""Return browser's original user agent.
|
||
|
|
||
|
.. note::
|
||
|
Pages can override browser user agent with
|
||
|
:meth:`pyppeteer.page.Page.setUserAgent`.
|
||
|
"""
|
||
|
...
|
||
|
|
||
|
async def close(self) -> None:
|
||
|
"""Close connections and terminate browser process."""
|
||
|
...
|
||
|
|
||
|
async def disconnect(self) -> None:
|
||
|
"""Disconnect browser."""
|
||
|
...
|
||
|
|
||
|
|
||
|
|
||
|
class BrowserContext(EventEmitter):
|
||
|
"""BrowserContext provides multiple independent browser sessions.
|
||
|
|
||
|
When a browser is launched, it has a single BrowserContext used by default.
|
||
|
The method `browser.newPage()` creates a page in the default browser
|
||
|
context.
|
||
|
|
||
|
If a page opens another page, e.g. with a ``window.open`` call, the popup
|
||
|
will belong to the parent page's browser context.
|
||
|
|
||
|
Pyppeteer allows creation of "incognito" browser context with
|
||
|
``browser.createIncognitoBrowserContext()`` method.
|
||
|
"incognito" browser contexts don't write any browser data to disk.
|
||
|
|
||
|
.. code::
|
||
|
|
||
|
# Create new incognito browser context
|
||
|
context = await browser.createIncognitoBrowserContext()
|
||
|
# Create a new page inside context
|
||
|
page = await context.newPage()
|
||
|
# ... do stuff with page ...
|
||
|
await page.goto('https://example.com')
|
||
|
# Dispose context once it's no longer needed
|
||
|
await context.close()
|
||
|
"""
|
||
|
Events = ...
|
||
|
def __init__(self, browser: Browser, contextId: Optional[str]) -> None:
|
||
|
...
|
||
|
|
||
|
def targets(self) -> List[Target]:
|
||
|
"""Return a list of all active targets inside the browser context."""
|
||
|
...
|
||
|
|
||
|
async def pages(self) -> List[Page]:
|
||
|
"""Return list of all open pages.
|
||
|
|
||
|
Non-visible pages, such as ``"background_page"``, will not be listed
|
||
|
here. You can find them using :meth:`pyppeteer.target.Target.page`.
|
||
|
"""
|
||
|
...
|
||
|
|
||
|
def isIncognite(self) -> bool:
|
||
|
"""[Deprecated] Miss spelled method.
|
||
|
|
||
|
Use :meth:`isIncognito` method instead.
|
||
|
"""
|
||
|
...
|
||
|
|
||
|
def isIncognito(self) -> bool:
|
||
|
"""Return whether BrowserContext is incognito.
|
||
|
|
||
|
The default browser context is the only non-incognito browser context.
|
||
|
|
||
|
.. note::
|
||
|
The default browser context cannot be closed.
|
||
|
"""
|
||
|
...
|
||
|
|
||
|
async def newPage(self) -> Page:
|
||
|
"""Create a new page in the browser context."""
|
||
|
...
|
||
|
|
||
|
@property
|
||
|
def browser(self) -> Browser:
|
||
|
"""Return the browser this browser context belongs to."""
|
||
|
...
|
||
|
|
||
|
async def close(self) -> None:
|
||
|
"""Close the browser context.
|
||
|
|
||
|
All the targets that belongs to the browser context will be closed.
|
||
|
|
||
|
.. note::
|
||
|
Only incognito browser context can be closed.
|
||
|
"""
|
||
|
...
|
||
|
|
||
|
|
||
|
|