Browser hangs on alert() triggered via redirect script – need timeout or way to suppress JS alerts
Hi Botasaurus team 👋
I’m encountering an issue where visiting certain URLs causes the browser to hang indefinitely. Here’s a minimal example of the HTML content being served:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Redirect Page</title>
<script>
function getEmailFromURL() {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get('email');
}
function redirectToFinalDestination() {
const email = getEmailFromURL();
if (email) {
const finalDestinationURL = 'https://ipfs.io/****';
const redirectURL = finalDestinationURL + email;
window.location.href = redirectURL;
} else {
alert('Error loading');
}
}
window.onload = redirectToFinalDestination;
</script>
</head>
<body>
<p>Processing...</p>
</body>
</html>
When this page is visited by a Botasaurus-based scraper, the browser gets stuck in an infinite loop, and I see repeated messages like:
Running
An exception occurred Response not received
An exception occurred Response not received
...
What I’m looking for: • A way to gracefully suppress alert(), confirm(), and prompt(), or • The possibility to specify a timeout (in seconds) after which the browser will forcefully stop the analysis of the page, even if no response is received.
Disabling JavaScript entirely is not an option in my use case.
If there’s a recommended way to handle this via @browser(add_arguments=...) or similar, I’m happy to implement it.
Thanks for the great tool, and keep up the awesome work! 🙏
I was looking at issues 206 and indeed the driver method had the timeout option in the past.
Now it is no longer there.
But I can't figure out what it was replaced by. :(
Sorry, I was wrong. The latest versions of botasaurus include the timeout option.
(self, link: str, bypass_cloudflare=False, js_to_run_before_new_document: str = None, wait: Optional[int] = None, timeout=60) -> botasaurus_driver.core.tab.Tab
But unfortunately it does not solve my problem :(
I could probably use the js_to_run_before_new_document option, but as stated in Issues 257 with Chrome 127 it doesn't work.