mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
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
27 lines
733 B
JavaScript
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);
|
|
});
|
|
|
|
|