-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(adblock): add brave adblock support
- Loading branch information
Showing
11 changed files
with
251 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { _log } from "./config"; | ||
import { Audit, kayle, RunnerConf } from "./kayle"; | ||
|
||
let write; | ||
let extractLinks; | ||
|
||
// on autoKayle link find callback | ||
declare function callback(audit: Audit): Audit; | ||
declare function callback(audit: Audit): Promise<Audit>; | ||
|
||
/** | ||
* Run accessibility tests for page auto running until all pages complete. | ||
* @param {Object} [config={}] config - Options to change the way tests run. | ||
* @returns {Promise} Returns a promise which resolves with array of results. | ||
*/ | ||
export async function autoKayle( | ||
o: RunnerConf & { log?: boolean; store?: string; cb?: typeof callback } = {}, | ||
ignoreSet?: Set<String>, | ||
_results?: Audit[] | ||
): Promise<Audit[]> { | ||
if (!write) { | ||
const { writeFile } = await import("fs/promises"); | ||
write = writeFile; | ||
} | ||
// pre init list | ||
if (!_results) { | ||
_results = []; | ||
} | ||
|
||
const result = await kayle(o, true); | ||
|
||
_results.push(result); | ||
|
||
if (o.cb && typeof o.cb === "function") { | ||
await o.cb(result); | ||
} | ||
|
||
// auto run links until finished. | ||
if (!extractLinks) { | ||
extractLinks = (await import("./wasm/extract")).extractLinks; | ||
} | ||
|
||
if (!ignoreSet) { | ||
ignoreSet = new Set(); | ||
} | ||
|
||
const links: string[] = await extractLinks(o); | ||
|
||
// persist html file to disk | ||
if (o.store) { | ||
await write( | ||
`${o.store}/${encodeURIComponent(o.page.url())}`, | ||
await o.page.content() | ||
); | ||
} | ||
|
||
await o.page.close(); | ||
|
||
await Promise.all( | ||
links.map(async (link) => { | ||
if (ignoreSet.has(link)) { | ||
return await Promise.resolve(); | ||
} | ||
|
||
if (_log.enabled) { | ||
console.log(`Running: ${link}`); | ||
} | ||
|
||
ignoreSet.add(link); | ||
|
||
return await autoKayle( | ||
{ | ||
...o, | ||
page: await o.browser.newPage(), | ||
html: null, | ||
origin: link, | ||
}, | ||
ignoreSet, | ||
_results | ||
); | ||
}) | ||
); | ||
|
||
return _results; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# data | ||
|
||
Things that help make kayle more efficient. | ||
|
||
1. [adblock](https://github.com/brave/adblock-rust) - Enabled by using the `process.env.KAYLE_ADBLOCK=true` or setting the env variable `KAYLE_ADBLOCK` to true. In order to use adblock you also need to run `npm i adblock-rs` to install the wasm module locally. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// get a list of valid things that help with data | ||
export const adblock = Symbol("adblock engine to ignore resources"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
export { | ||
kayle, | ||
setLogging, | ||
autoKayle, | ||
Issue, | ||
Audit, | ||
MetaInfo, | ||
Automatable, | ||
} from "./kayle"; | ||
export { kayle, Issue, Audit, MetaInfo, Automatable } from "./kayle"; | ||
export { autoKayle } from "./auto"; | ||
export { runnersJavascript } from "./runner-js"; | ||
export { | ||
goToPage, | ||
setNetworkInterception, | ||
networkBlock, | ||
} from "./utils/go-to-page"; | ||
export { setLogging } from "./config"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.