@w0s/closest-html-page
v5.0.2
Published
Get the data of the HTML page of the nearest ancestor hierarchy
Readme
Get the data of the HTML page of the nearest ancestor hierarchy
Demo
Examples
<script type="importmap">
{
"imports": {
"@w0s/closest-html-page": "...",
"whatwg-mimetype": "..."
}
}
</script>
<script type="module">
import closestHTMLPage from '@w0s/closest-html-page';
const { fetchedResponses, closestHTMLPageData } = await closestHTMLPage('https://example.com/path/to/file', {
maxFetchCount: 3,
fetchOptions: {
redirect: 'error',
},
mimeTypes: ['text/html'],
});
const url = closestHTMLPageData?.url;
const title = closestHTMLPageData?.title;
</script>Functions
closestHTMLPage(baseUrl = location.toString(), options?: Readonly<Option>): Promise<{
fetchedResponses: Response[]; // `Response` data resulting from the execution of `fetch()`
closestHTMLPageData: {
url: string; // URL of the HTML page
title: string | undefined; // Title of the HTML page
} | undefined;
}>Parameters
Option
interface Option {
maxFetchCount?: number;
fetchOptions?: RequestInit;
mimeTypes?: readonly DOMParserSupportedType[];
}