import * as Axe from 'axe-core' ; import { Browser , Page } from 'puppeteer' ; import { AxePuppeteer } from './axePuppeteer' ; import { AnalyzeCB , IPageOptions } from './types' ; class OwningAxePuppeteer extends AxePuppeteer { private page : Page ; constructor ( page , source ? ) { super ( page , source ) ; this . page = page ; } public async analyze ( ) ; public async analyze < T extends AnalyzeCB > ( callback ? ) ; public async analyze < T extends AnalyzeCB > ( callback ? ) { try { return await super . analyze ( callback ) ; } finally { await this . page . close ( ) ; } } } export async function loadPage ( browser , url , pageOpts = { } ) { const page = await browser . newPage ( ) ; await page . setBypassCSP ( true ) ; await page . goto ( url , pageOpts . opts ) ; return new OwningAxePuppeteer ( page , pageOpts . source ) ; }