I accepted @Fiximan's answer because it solves the problem mentioned in the question. In my particular case though (I try to print a website with a lot of MathJax formulas) his solution doesn't work because after loading the page the formulas are still rendering. If you have a similar case where you need to wait until the page is loaded AND some rendering processes are finished then you can use the following solution: You have to add some JavaScript to the page source to make it work. So either the site is yours or you have to download the page, manipulate the source code and start some local server.
General solution
If you want to call a bash script after a page has finished loading (incl. javascript):
HTML
<!DOCTYPE html>
<html>
<head>
<title>This is the page title</title>
<script>
// Save the page title in a variable
let pageTitle = document.title;
// Set the page title to something like...
document.title = "Page is loading..."
// If page has finished loading
document.addEventListener("DOMContentLoaded", function(event) {
// Set page title to original page title
document.title = pageTitle;
});
</script>
</head>
<body>
<h1>Hello world!</h1>
</body>
</html>
Bash
# Open new tab
firefox -new-tab "www.domain.tld"
# Wait 1 second
sleep 1
# Wait until page has finished loading...
while (xdotool search --name "Page is loading... - Mozilla Firefox" > /dev/null 2>&1) ; do
sleep 0.1
done
# Then execute new command
# < some command >
MathJax 3 solution
In my case I want to wait until the page has finished loading and MathJax has finished rendering. So I have to move the part "Set page title to original page title" to the MathJax configuration:
<script>
window.MathJax = {
// ...
// < your configurations >
// ...
startup: {
// If page has finished loading
pageReady() {
// If MathJax has finished typesetting
return MathJax.startup.defaultPageReady().then(function() {
// Set page title to original page title
document.title = "This is the page title";
});
}
}
{{ end }}
};
</script>