简体   繁体   中英

PhantomJS error: Cannot access member 'write' of deleted QObject

I need to create web api on port 7788 which will accept json, then pass that json to my api which will render website, and then phantom js will find element on that page and web api on port 7788 should return that element. Everything's go well till moment I try to send reponse to my server on 7788, error:

cannot access member `write' of deleted QObject:

for this: firstResponse.write(imgsrc);

Is it possible to return element with server.listen response after page.open is called?

var server = require('webserver').create();
    var port = require('system').env.PORT || 7788;

    server.listen(port, {'keepAlive': false}, function (request, response) {

        console.log("request method: ", request.method);  // request.method POST or GET    
            var imgsrc;
            var firstResponse = response;

        if (request.method == 'POST') {

            var page = require('webpage').create();
            var settings = {
              operation: "POST",
              encoding: "utf8",
              headers: {
                "Content-Type": "application/json"
              },
              data: JSON.stringify(request.post)
            };
            var url = "http://127.0.0.1:5000/mapapp";

             page.onConsoleMessage = function(msg, lineNum, sourceId) {
                console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
            }; 

            page.open(url, settings, function (status) {


                setTimeout(function () {
                    page.evaluate(function () { 

                        imgsrc = document.getElementById("exportedImg").src;
                    });

                }, 5000);
            });
            page.close();
            setTimeout(function () {
                    firstResponse.write(imgsrc);

                }, 7000);
        firstResponse.close(); 

        }


    });

You call firstResponse.close(); before is called firstResponse.write(imgsrc); after your timeout. Move firstResponse.close() to setTimeout handler:

page.close();
setTimeout(function () {
            firstResponse.write(imgsrc);
            firstResponse.close(); 
}, 7000);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM