Skip to content

Commit

Permalink
Add a timeout to the Google check
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Abraham <cjyabraham@gmail.com>
  • Loading branch information
cjyabraham committed Jul 19, 2024
1 parent def3540 commit 4c79d66
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,15 @@
}

async function checkBlockedSite(url) {
const controller = new AbortController();
const timeout = setTimeout(() => {
controller.abort();
}, 5000); // Timeout set to 5000ms (5 seconds)

try {
const response = await fetch(url, { method: 'HEAD', mode: 'no-cors' });
const response = await fetch(url, { method: 'HEAD', mode: 'no-cors', signal: controller.signal });
// If we reach this point, the site is accessible (since mode: 'no-cors' doesn't allow us to check response.ok)
clearTimeout(timeout);
return false;
} catch (error) {
// If an error occurs, it's likely the site is blocked
Expand Down

0 comments on commit 4c79d66

Please sign in to comment.