diff --git a/kayle/lib/config.ts b/kayle/lib/config.ts index 0c66612..633073c 100644 --- a/kayle/lib/config.ts +++ b/kayle/lib/config.ts @@ -80,16 +80,18 @@ export type WaitForOptions = { }; // playwright mouse actions -type DefaultMouseActions = { - delay?: number; - clickCount?: number; - button?: "left"|"right"|"middle" -} | number; +type DefaultMouseActions = + | { + delay?: number; + clickCount?: number; + button?: "left" | "right" | "middle"; + } + | number; type Point = { - x?: number - y?: number -} + x?: number; + y?: number; +}; // puppeteer mouse events type MouseActions = { @@ -110,12 +112,9 @@ type MouseActions = { source: number | Readonly | unknown, target?: number, ): Promise; - move?( - source: number, - target: number, - ): Promise; + move?(source: number, target: number): Promise; wheel?( - deltaX: number | Readonly<{x: number, y: number}> | unknown, + deltaX: number | Readonly<{ x: number; y: number }> | unknown, deltaY?: number, ): Promise; reset?(): Promise; @@ -125,7 +124,7 @@ type MouseActions = { options?: { delay?: number; clickCount?: number; - button?: "left"|"right"|"middle" + button?: "left" | "right" | "middle"; }, ): Promise; dblclick?( @@ -134,7 +133,7 @@ type MouseActions = { options?: { delay?: number; clickCount?: number; - button?: "left"|"right"|"middle" + button?: "left" | "right" | "middle"; }, ): Promise; }; @@ -278,6 +277,8 @@ export type RunnerConfig = { noIntercept?: boolean; // run as accesibility extension: Experimental. Must setup extensions with the browser before hand. browserExtension?: boolean; + /// Dismiss all dialogs that appear. By default it will dismiss all dialogs. + dialogHandle?: { action?: "dismiss" | "accept"; promptText?: string }; // watch config _watcher?: Watcher; // initial fake request ran to enable Js diff --git a/kayle/lib/kayle.ts b/kayle/lib/kayle.ts index 3bdb95b..439929b 100644 --- a/kayle/lib/kayle.ts +++ b/kayle/lib/kayle.ts @@ -170,6 +170,20 @@ export const kayle = async ( const config = extractArgs(o, watcher); let validPage = true; + if (o.dialogHandle) { + o.page.on("dialog", async (dialog) => { + try { + if (o.dialogHandle.action === "accept") { + await dialog.accept(o.dialogHandle.promptText); + } else { + await dialog.dismiss(); + } + } catch(e) { + // memory could be full - simply ignore the log + } + }); + } + if (navigate) { validPage = await goToPage(o); } else if (!o.noIntercept) { diff --git a/kayle/lib/rules/index.ts b/kayle/lib/rules/index.ts index 3e40ea0..76985fb 100644 --- a/kayle/lib/rules/index.ts +++ b/kayle/lib/rules/index.ts @@ -67,9 +67,7 @@ export const importRules = async ( 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 10345a5..263c0ed 100644 --- a/kayle/package.json +++ b/kayle/package.json @@ -1,6 +1,6 @@ { "name": "kayle", - "version": "0.8.50", + "version": "0.8.51", "description": "Extremely fast and accurate accessibility engine built for any headless tool like playwright or puppeteer.", "main": "./build/index.js", "keywords": [