diff --git a/kayle/lib/kayle.ts b/kayle/lib/kayle.ts index b686427..0918493 100644 --- a/kayle/lib/kayle.ts +++ b/kayle/lib/kayle.ts @@ -168,61 +168,81 @@ export const kayle = async ( const watcher = new Watcher(); const navigate = o.page.url() === "about:blank" && (o.origin || o.html); const config = extractArgs(o, watcher); + let validPage = true; if (navigate) { - await goToPage(o); + validPage = await goToPage(o); } else if (!o.noIntercept) { await setNetworkInterception(o); } - const results = await Promise.race([ - watcher.watch(config.timeout), - auditPage(config), - ]); + if (validPage) { + const results = await Promise.race([ + watcher.watch(config.timeout), + auditPage(config), + ]); - clearTimeout(watcher.timer as number); + clearTimeout(watcher.timer as number); + + if (results && o.clip && o.clip2Base64 && Array.isArray(results.issues)) { + results.issues = await Promise.all( + results.issues.map(async (item) => { + // prevent screenshots + if (typeof o.clipMax === "number") { + if (!o.clipMax) { + return item; + } + o.clipMax--; + } - if (results && o.clip && o.clip2Base64 && Array.isArray(results.issues)) { - results.issues = await Promise.all( - results.issues.map(async (item) => { - // prevent screenshots - if (typeof o.clipMax === "number") { - if (!o.clipMax) { - return item; + try { + const buffer = await o.page.screenshot({ + path: o.clipDir + ? `${o.clipDir}${ + o.clipDir.endsWith("/") ? "" : "/" + }${item.selector.trim()}.png` + : undefined, + clip: item.clip, + }); + + // use a dynamic property to inject - todo: set the config initially before this iteration to keep shape aligned. + item.clipBase64 = buffer.toString("base64"); + } catch (_) { + // most likely not in the viewport + // console.error(e); + item.clipBase64 = ""; } - o.clipMax--; - } - try { - const buffer = await o.page.screenshot({ - path: o.clipDir - ? `${o.clipDir}${ - o.clipDir.endsWith("/") ? "" : "/" - }${item.selector.trim()}.png` - : undefined, - clip: item.clip, - }); - - // use a dynamic property to inject - todo: set the config initially before this iteration to keep shape aligned. - item.clipBase64 = buffer.toString("base64"); - } catch (_) { - // most likely not in the viewport - // console.error(e); - item.clipBase64 = ""; - } + return item; + }) + ); + } - return item; - }) - ); - } + if (!preventClose && navigate) { + try { + await config.page.close(); + } catch (e) { + _log.enabled && console.error(e); + } + } - if (!preventClose && navigate) { - try { - await config.page.close(); - } catch (e) { - _log.enabled && console.error(e); + return results; + } else { + if (!preventClose && navigate) { + try { + await config.page.close(); + } catch (e) { + _log.enabled && console.error(e); + } } - } - return results; + return null; + // return { + // automateable: null, + // documentTitle: "", + // issues: [], + // meta: null, + // pageUrl: config.origin + // } + } }; diff --git a/kayle/lib/rules/index.ts b/kayle/lib/rules/index.ts index 76985fb..bad7355 100644 --- a/kayle/lib/rules/index.ts +++ b/kayle/lib/rules/index.ts @@ -64,10 +64,12 @@ export const importRules = async ( | "pt_BR" | "en", runner: "htmlcs" | "axe", - baseDir?: "string", + baseDir?: "string" ): Promise => { const rules = await import( - `${baseDir || "./"}${locale.replace("-", "_")}/${runner === "htmlcs" ? "htmlcs" : "axe"}-rules` + `${baseDir || "./"}${locale.replace("-", "_")}/${ + runner === "htmlcs" ? "htmlcs" : "axe" + }-rules` ); return rules.axeRules || rules.htmlcsRules; diff --git a/kayle/package.json b/kayle/package.json index 3946c21..7a64c10 100644 --- a/kayle/package.json +++ b/kayle/package.json @@ -1,6 +1,6 @@ { "name": "kayle", - "version": "0.8.46", + "version": "0.8.47", "description": "Extremely fast and accurate accessibility engine built for any headless tool like playwright or puppeteer.", "main": "./build/index.js", "keywords": [