effect-playwright
    Preparing search index...

    Interface Coverage

    Coverage gathers information about parts of JavaScript and CSS that were used by the page.

    An example of using JavaScript coverage to produce Istanbul report for page load:

    NOTE Coverage APIs are only supported on Chromium-based browsers.

    const { chromium } = require('playwright');
    const v8toIstanbul = require('v8-to-istanbul');

    (async () => {
    const browser = await chromium.launch();
    const page = await browser.newPage();
    await page.coverage.startJSCoverage();
    await page.goto('https://chromium.org');
    const coverage = await page.coverage.stopJSCoverage();
    for (const entry of coverage) {
    const converter = v8toIstanbul('', 0, { source: entry.source });
    await converter.load();
    converter.applyCoverage(entry.functions);
    console.log(JSON.stringify(converter.toIstanbul()));
    }
    await browser.close();
    })();
    interface Coverage {
        startCSSCoverage(
            options?: { resetOnNavigation?: boolean },
        ): Promise<void>;
        startJSCoverage(
            options?: {
                reportAnonymousScripts?: boolean;
                resetOnNavigation?: boolean;
            },
        ): Promise<void>;
        stopCSSCoverage(): Promise<
            {
                ranges: { end: number; start: number }[];
                text?: string;
                url: string;
            }[],
        >;
        stopJSCoverage(): Promise<
            {
                functions: {
                    functionName: string;
                    isBlockCoverage: boolean;
                    ranges: { count: number; endOffset: number; startOffset: number }[];
                }[];
                scriptId: string;
                source?: string;
                url: string;
            }[],
        >;
    }

    Hierarchy (View Summary)

    Index
    • Returns coverage is started

      Parameters

      • Optionaloptions: { resetOnNavigation?: boolean }
        • OptionalresetOnNavigation?: boolean

          Whether to reset coverage on every navigation. Defaults to true.

      Returns Promise<void>

    • Returns coverage is started

      NOTE Anonymous scripts are ones that don't have an associated url. These are scripts that are dynamically created on the page using eval or new Function. If reportAnonymousScripts is set to true, anonymous scripts will have __playwright_evaluation_script__ as their URL.

      Parameters

      • Optionaloptions: { reportAnonymousScripts?: boolean; resetOnNavigation?: boolean }
        • OptionalreportAnonymousScripts?: boolean

          Whether anonymous scripts generated by the page should be reported. Defaults to false.

        • OptionalresetOnNavigation?: boolean

          NOTE Settings this to false may still reset on navigations.

          Whether to reset coverage on every navigation. Defaults to true. Note that passing false does not guarantee that coverage persists through navigations, due to browser architecture limitations.

      Returns Promise<void>

    • Returns the array of coverage reports for all stylesheets

      NOTE CSS Coverage doesn't include dynamically injected style tags without sourceURLs.

      Returns Promise<
          { ranges: { end: number; start: number }[]; text?: string; url: string }[],
      >

    • Returns the array of coverage reports for all scripts

      NOTE JavaScript Coverage doesn't include anonymous scripts by default. However, scripts with sourceURLs are reported.

      Returns Promise<
          {
              functions: {
                  functionName: string;
                  isBlockCoverage: boolean;
                  ranges: { count: number; endOffset: number; startOffset: number }[];
              }[];
              scriptId: string;
              source?: string;
              url: string;
          }[],
      >