Skip to content

Commit

Permalink
chore(page): add valid page for auditing
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Mar 22, 2024
1 parent bb57bf1 commit 708aa0c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 46 deletions.
106 changes: 63 additions & 43 deletions kayle/lib/kayle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
// }
}
};
6 changes: 4 additions & 2 deletions kayle/lib/rules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ export const importRules = async (
| "pt_BR"
| "en",
runner: "htmlcs" | "axe",
baseDir?: "string",
baseDir?: "string"
): Promise<Rule[]> => {
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;
Expand Down
2 changes: 1 addition & 1 deletion kayle/package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down

0 comments on commit 708aa0c

Please sign in to comment.