See #169
Create HTML fetcher #170
quokka/doipjs:add-html into dev c1d6f2b03e
to 752eccf6a3
I have the gut feeling that we can have XSS enabled here. We likely should add sanitisation into the mix.
@ -23,8 +23,10 @@
"@xmpp/debug": "^0.13.0",
"axios": "^1.6.5",
"browser-or-node": "^1.3.0",
"cheerio": "^1.0.0",
We might be able to use smaller libraries. For example htmlparser2 is used by cheerio.
I haven't looked into these solutions, but do any of them have a way to query the DOM?
They do. I've studied cheerios source code and it also supports parse5. Combined with its sanctioned tools we can safe a couple of bytes here :)
@ -0,0 +1,74 @@
/*
Copyright 2021 Daniel Levi
Blast from the past 🤪
@ -0,0 +18,4 @@
* @module fetcher/html
* @example
* import { fetcher } from 'doipjs';
* const data = await fetcher.html.fn({ url: 'https://example.com', query: '#example' });
# is introducing a fragment. Queries use ?.
@ -0,0 +37,4 @@
* @function
* @param {object} data - Data used in the request
* @param {string} data.url - The URL to verify
* @param {string} data.query - The DOM query of the claim
Ah, got it. You mean selector instead of query.
@ -0,0 +40,4 @@
* @param {string} data.query - The DOM query of the claim
* @param {number} [data.fetcherTimeout] - Optional timeout for the fetcher
* @param {import('../types').VerificationConfig} [opts] - Options used to enable the request
* @returns {Promise<object[]>} The fetched HTML element(s) as objects
I prefer Promise<Array<object>> as notation, but this is personal taste.
Let's start from here.
8a60c25f1a
to a11c26a0aa
Archived
Archived
No due date set.
No dependencies set.
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?