Files
meteor/packages/spiderable/phantom_script.js
MaximDubrovin 6345d92f07 move phantom_script.js setInterval into page.open callback
Until I made this I always got only ```<head/>``` with it's content, ```<body>``` was empty.

It seems setInterval script was finished earlier then url content was loaded to the page. Maybe because I have subscriptions with response time lower then 100ms so they were ready very quickly — database server in the same data center.

http://phantomjs.org/api/webpage/method/open.html
2014-08-01 16:44:04 -07:00

27 lines
733 B
JavaScript

// 'url' is assigned to in a statement before this.
var page = require('webpage').create();
page.open(url, function(status) {
if (status === 'fail')
phantom.exit();
setInterval(function() {
var ready = page.evaluate(function () {
if (typeof Meteor !== 'undefined'
&& typeof(Meteor.status) !== 'undefined'
&& Meteor.status().connected) {
Deps.flush();
return DDP._allSubscriptionsReady();
}
return false;
});
if (ready) {
var out = page.content;
out = out.replace(/<script[^>]+>(.|\n|\r)*?<\/script\s*>/ig, '');
out = out.replace('<meta name="fragment" content="!">', '');
console.log(out);
phantom.exit();
}
}, 100);
});