sphinx_pyppeteer_builder/typings/pyppeteer/coverage.pyi

145 lines
4.7 KiB
Python

"""
This type stub file was generated by pyright.
"""
from typing import Any, Dict, List
from pyppeteer.connection import CDPSession
"""Coverage module."""
logger = ...
class Coverage:
"""Coverage class.
Coverage gathers information about parts of JavaScript and CSS that were
used by the page.
An example of using JavaScript and CSS coverage to get percentage of
initially executed code::
# Enable both JavaScript and CSS coverage
await page.coverage.startJSCoverage()
await page.coverage.startCSSCoverage()
# Navigate to page
await page.goto('https://example.com')
# Disable JS and CSS coverage and get results
jsCoverage = await page.coverage.stopJSCoverage()
cssCoverage = await page.coverage.stopCSSCoverage()
totalBytes = 0
usedBytes = 0
coverage = jsCoverage + cssCoverage
for entry in coverage:
totalBytes += len(entry['text'])
for range in entry['ranges']:
usedBytes += range['end'] - range['start'] - 1
print('Bytes used: {}%'.format(usedBytes / totalBytes * 100))
"""
def __init__(self, client: CDPSession) -> None:
...
async def startJSCoverage(self, options: Dict[str, Any] = ..., **kwargs: Any) -> None:
"""Start JS coverage measurement.
Available options are:
* ``resetOnNavigation`` (bool): Whether to reset coverage on every
navigation. Defaults to ``True``.
* ``reportAnonymousScript`` (bool): Whether anonymous script generated
by the page should be reported. Defaults to ``False``.
.. note::
Anonymous scripts are ones that don't have an associated url. These
are scripts that are dynamically created on the page using ``eval``
of ``new Function``. If ``reportAnonymousScript`` is set to
``True``, anonymous scripts will have
``__pyppeteer_evaluation_script__`` as their url.
"""
...
async def stopJSCoverage(self) -> List:
"""Stop JS coverage measurement and get result.
Return list of coverage reports for all scripts. Each report includes:
* ``url`` (str): Script url.
* ``text`` (str): Script content.
* ``ranges`` (List[Dict]): Script ranges that were executed. Ranges are
sorted and non-overlapping.
* ``start`` (int): A start offset in text, inclusive.
* ``end`` (int): An end offset in text, exclusive.
.. note::
JavaScript coverage doesn't include anonymous scripts by default.
However, scripts with sourceURLs are reported.
"""
...
async def startCSSCoverage(self, options: Dict[str, Any] = ..., **kwargs: Any) -> None:
"""Start CSS coverage measurement.
Available options are:
* ``resetOnNavigation`` (bool): Whether to reset coverage on every
navigation. Defaults to ``True``.
"""
...
async def stopCSSCoverage(self) -> List:
"""Stop CSS coverage measurement and get result.
Return list of coverage reports for all non-anonymous scripts. Each
report includes:
* ``url`` (str): StyleSheet url.
* ``text`` (str): StyleSheet content.
* ``ranges`` (List[Dict]): StyleSheet ranges that were executed. Ranges
are sorted and non-overlapping.
* ``start`` (int): A start offset in text, inclusive.
* ``end`` (int): An end offset in text, exclusive.
.. note::
CSS coverage doesn't include dynamically injected style tags without
sourceURLs (but currently includes... to be fixed).
"""
...
class JSCoverage:
"""JavaScript Coverage class."""
def __init__(self, client: CDPSession) -> None:
...
async def start(self, options: Dict[str, Any] = ..., **kwargs: Any) -> None:
"""Start coverage measurement."""
...
async def stop(self) -> List:
"""Stop coverage measurement and return results."""
...
class CSSCoverage:
"""CSS Coverage class."""
def __init__(self, client: CDPSession) -> None:
...
async def start(self, options: Dict[str, Any] = ..., **kwargs: Any) -> None:
"""Start coverage measurement."""
...
async def stop(self) -> List:
"""Stop coverage measurement and return results."""
...
def convertToDisjointRanges(nestedRanges: List[Any]) -> List[Any]:
"""Convert ranges."""
...