Skip to content

Commit 4c79d66

Browse files
committed
Add a timeout to the Google check
Signed-off-by: Chris Abraham <[email protected]>
1 parent def3540 commit 4c79d66

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

static/js/search.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,15 @@
6969
}
7070

7171
async function checkBlockedSite(url) {
72+
const controller = new AbortController();
73+
const timeout = setTimeout(() => {
74+
controller.abort();
75+
}, 5000); // Timeout set to 5000ms (5 seconds)
76+
7277
try {
73-
const response = await fetch(url, { method: 'HEAD', mode: 'no-cors' });
78+
const response = await fetch(url, { method: 'HEAD', mode: 'no-cors', signal: controller.signal });
7479
// If we reach this point, the site is accessible (since mode: 'no-cors' doesn't allow us to check response.ok)
80+
clearTimeout(timeout);
7581
return false;
7682
} catch (error) {
7783
// If an error occurs, it's likely the site is blocked

0 commit comments

Comments
 (0)