Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js NodejS+;PhantomJS warn:exit()是在等待命令完成之前调用的。确保没有过早调用exit()_Node.js_Phantomjs - Fatal编程技术网

Node.js NodejS+;PhantomJS warn:exit()是在等待命令完成之前调用的。确保没有过早调用exit()

Node.js NodejS+;PhantomJS warn:exit()是在等待命令完成之前调用的。确保没有过早调用exit(),node.js,phantomjs,Node.js,Phantomjs,尝试使用PhantomJS和NodeJS来检查网站加载时间 但是在那之后我收到了这个消息 phantom_instance.exit(); 已尝试在承诺返回后运行此线路 这是我的密码: function timer(url) { return new Promise(function(resolve, reject) { let phantom_instance = null; let sitepage = null; let start_time = null;

尝试使用PhantomJS和NodeJS来检查网站加载时间

但是在那之后我收到了这个消息

phantom_instance.exit();
已尝试在承诺返回后运行此线路

这是我的密码:

function timer(url) {
return new Promise(function(resolve, reject) {
    let phantom_instance = null;
    let sitepage = null;
    let start_time = null;
    let end_time = null;
    let interval_obj = null;
    let loading_time = 0;
    phantom.create()
        .then(function(instance) {
            phantom_instance = instance;
            return phantom_instance.createPage();
        })
        .then(function(page) {
            sitepage = page;
            page.property('viewportSize', {
                width: 1280,
                height: 1024
            })
            start_time = Date.now();
            return page.open(url);
        })
        .then(function(status) {
            return new Promise(function(resolve, reject) {
                if (status == 'success') {
                    interval_obj = setInterval(function() {
                        //tell the browser to return document.readyStatue
                        sitepage.evaluate(function() {
                            return document.readyState;
                        })
                        .then(function(ready_state) {
                            if (ready_state == "complete") {
                                end_time = Date.now();
                                sitepage.close();
                                clearInterval(interval_obj);
                                loading_time = end_time - start_time;
                                return resolve(loading_time);
                            } else {
                                console.log(ready_state);
                            }
                        })
                    }, 1000);
                } else {
                    //phantom_instance.exit();
                    return reject(status);
                }
            });
        })
        .then(function(loading_time) {
            console.log("[Speed Tester] Completed in : " + loading_time);
            phantom_instance.exit();
            return resolve({time:loading_time});
        })
});
}
有什么想法吗


谢谢。

在执行
phantom\u instance.exit()
之前,通过执行并等待承诺得到解决,我可以避免上述警告