The purpose of this question is to exclude any errors in my javascript code, as I am new to this language.
According to this answer, I use the following code to reload a website in a phantomJS
context in case the initial loading takes longer than a certain threshold:
var timer; // Define timeout outside function
this.onLoadFinished = function(){ // If page is loaded
window.clearTimeout(timer); // Clear timeout function
console.log("Page loaded - CLEAR timeout"); // Announce cleared timeout
timer = window.setTimeout(function(){ // And set new timeout
console.log("SET Timeout for page load"); // Announce set timeout
window.location.reload(); // Reload page
console.log("PAGE reloaded") // Announce reload
}, 90000); // After 90 sec
};
In the resulting Ghostdriver.log
, I can see that the timeout has been set and cleared. Also, the reload is indicated.
However, the reload doesn't happen because my script indefinitely hangs:
phantomjs://platform/console++.js:263 in error
Page loaded - CLEAR timeout
SET Timeout for page load
PAGE reloaded
[INFO - 2018-03-30T01:40:56.448Z] SessionManagerReqHand -
_cleanupWindowlessSessions - Asynchronous Sessions clean-up phase starting NOW
[ERROR - 2018-03-30T01:37:11.140Z] RouterReqHand -
_handle.error - {"name":"Missing Command Parameter","message":.....[shortened]
Question:
How to properly reload a page in case of timeout in a javascript phantomJS
context?
Another solution I have tried is this:
this.settings.ressourceTimeout = 90000
this.onRessourceTimeout = function(){
this.reload();
This didn't work either, for reasons summarized in great detail here (in a nutshell, As of phantomJS
1.9.8 and its embedded Ghostdriver
, resourceTimeout
won't be applied by Ghostdriver
).