Recently, I have been experimenting with PhantomJS to capture screenshots of a webpage every five minutes. While the process runs smoothly most of the time, I encountered an issue where the AngularJS library fails to load intermittently. This results in the inability to render the page correctly. To address this challenge, I am actively exploring ways to incorporate a local copy in place of the missing library. Here is what I have attempted so far...
var page = require('webpage').create(),system = require('system');
var home = 'https://smartway.tn.gov/traffic/';
page.open(home, function (status) {
if(status === "success"){
page.injectJs('angular.js');
window.setTimeout((function() {
page.evaluate(function () {
/*stuff*/
});
}), 2000);
}
});
The file angular.js serves as my offline version of the script that would typically be fetched by the site. Normally, the website imports this script along with others at the end of the body. I am presently investigating the optimal approach for its inclusion. One conjecture is that it may need to replace the respective script tag within the HTML document to ensure proper sequencing during loading. However, executing this substitution technique remains unclear to me.
I appreciate any insights or suggestions on this matter.