@w0s/report-same-referrer
v3.0.1
Published
Send referrer error information to endpoints
Downloads
13
Readme
Send referrer error information to endpoints
If there are referrers from same site, that information will be sent to the endpoint as an error.
As a practical use case, this script put this script in error pages like 403, 404, 410 error pages to detect the existence of broken links in the same site.
Demo
Examples
<script type="importmap">
{
"imports": {
"@w0s/report-same-referrer": "..."
}
}
</script>
<script type="module">
import ReportSameReferrer from '@w0s/report-same-referrer';
const reportSameReferrer = new ReportSameReferrer('https://report.example.com/referrer', {
fetchParam: {
location: 'loc',
referrer: 'ref',
},
fetchContentType: 'application/json',
fetchHeaders: {
'X-Requested-With': 'hoge',
},
condition: 'origin',
same: [
'https://www1.example.com',
'https://www2.example.com',
],
denyUAs: [
/Googlebot\/2.1;/,
],
});
await reportSameReferrer.report();
</script>
Constructor
new ReportSameReferrer(endpoint: string, options?: Option)
Parameters
Option
interface Option {
fetchParam?: {
location: string;
referrer: string;
};
fetchContentType?: 'application/x-www-form-urlencoded' | 'application/json';
fetchHeaders?: HeadersInit;
condition?: 'origin' | 'host' | 'hostname';
same?: string[];
denyUAs?: RegExp[];
allowUAs?: RegExp[];
}