Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Rendering to stdout fails #14059

Closed
slorber opened this issue Mar 2, 2016 · 6 comments
Closed

Rendering to stdout fails #14059

slorber opened this issue Mar 2, 2016 · 6 comments
Labels

Comments

@slorber
Copy link

slorber commented Mar 2, 2016

var page = require('webpage').create();
page.viewportSize = { width: 1200, height: 800 };



page.open('http://localhost:3000/', function() {

  setInterval(function() {
    page.render("/dev/stdout");
    page.render("test2.png");
    phantom.exit()
  }, 5000);

});

I run phantomjs recorder.js >> test.png

This works with 1.9.7
This does not work with 2.1.1

In 2.1.1, test.png remains empty while content was expected

@slorber slorber changed the title Rendering to stdout does not work anymore Rendering to stdout fails Mar 2, 2016
@slorber
Copy link
Author

slorber commented Mar 2, 2016

Sorry, I'm not sure what is happening, it seems it has worked but not anymore...

sebastien@sebastien-xps:todomvc (master *%)$ node -v
v4.2.3
sebastien@sebastien-xps:todomvc (master *%)$ npm -v
2.14.7
sebastien@sebastien-xps:todomvc (master *%)$ phantomjs -v
2.1.1

I'm running

var page = require('webpage').create();
var fs = require("fs");

page.viewportSize = { width: 1200, height: 800 };

page.open('http://localhost:3000/', function() {

  setInterval(function() {
    fs.write("/dev/stdout", page.renderBase64(), "w");
  }, 1000);

});
sebastien@sebastien-xps:todomvc (master *%)$ phantomjs recorder.js
Unable to open file '/dev/stdout'

  phantomjs://platform/fs.js:79 in open
  phantomjs://platform/fs.js:136 in write
  phantomjs://code/recorder.js:13
Unable to open file '/dev/stdout'

  phantomjs://platform/fs.js:79 in open
  phantomjs://platform/fs.js:136 in write
  phantomjs://code/recorder.js:13
Unable to open file '/dev/stdout'

  phantomjs://platform/fs.js:79 in open
  phantomjs://platform/fs.js:136 in write
  phantomjs://code/recorder.js:13
PhantomJS has crashed. Please read the bug reporting guide at
<http://phantomjs.org/bug-reporting.html> and file a bug report.

@slorber
Copy link
Author

slorber commented Mar 3, 2016

Sorry I don't really understand what is happening there.

It seems to fail when I install phantomjs with npm install phantomjs -g, but it works when I install it with sudo apt-get install phantomjs.

Note that I tried to launch phantomjs with sudo and did not work better. I also used in both cases the 1.9.0 version which is available on apt-get and npm, and got different results.

Any idea why it fails when installed through npm (on ubuntu?). It was the case on my laptop, and on a remote server running a more recent version of ubuntu.

@ariya
Copy link
Owner

ariya commented Mar 3, 2016

The report is a bit confusing. I think you need to summarize it again so we all can understand clearly in which situation(s) the rendering does not as expected. In each situation, please provide the information on:

  • the PhantomJS version: phantomjs --version
  • the system information: uname -a
  • OS details and version: lsb_release -a

Also, if possible, eliminate the case where you install PhantomJS via npm because we do not own or control that module. You have to bring up any problem with npm package to https://github.com/Medium/phantomjs.

Thank you!

@slorber
Copy link
Author

slorber commented Mar 3, 2016

@ariya to sum it up, I don't exactly know what happens, but here are some insights:

Script to run: recorder.js

var page = require('webpage').create();

page.open('http://blog.zenika.com/', function() {

  setTimeout(function() {
    page.render("/dev/stdout",{ format: "png" });
    phantom.exit()
  }, 1000);

});

System info

I tested this on 2 distinct systems and got the same result

Linux sebastien-xps 3.13.0-66-generic #108~precise1-Ubuntu SMP Thu Oct 8 10:07:36 UTC 2015 

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 12.04.5 LTS
Release:    12.04
Codename:   precise
Linux dev 3.13.0-65-generic #105-Ubuntu SMP Mon Sep 21 18:50:58 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.3 LTS
Release:    14.04
Codename:   trusty

Test 1

sudo apt-get install phantomjs

phantomjs -v -> returns 1.9.0

phantomjs recorder.js -> outputs binary data

Test 2

sudo npm install -g [email protected]

phantomjs -v -> returns 1.9.0

phantomjs recorder.js -> outputs nothing


@ariya I'll open an issue on the medium repository as it seems related to it only. I thought medium only handled the phantomjs-prebuild and that you managed the phantomjs package but it seems it's not the case and medium handles both.

@BlackCapCoder
Copy link

BlackCapCoder commented Sep 28, 2017

I am also suffering from this. This occurs with all writes to stdout, not just page.render. It is possible to "flush" the data out by writing more things to stdout/stdin.

const sys = require('system');
const inp = sys.stdin;
const out = sys.stdout;
const wp  = require('webpage');

var inst = new lorem ();

function lorem () {
  this.run = function (inp) {
    eval(inp);
  };

  this.ping = function () {
    out.writeLine("pong");
  }

  this.Open = function (url) {
    var page = wp.create();
    page.open("http://example.com", function(status) {
      out.writeLine("OK");
    });
  };
}

function listenIO () {
  setTimeout(function () {
    var ln = inp.readLine();
    inst.run(ln);
    // out.flush(); doesn't matter
    listenIO();
  }, 0);
}
listenIO();
$ phantomjs main.js
this.ping()
pong
this.ping()
pong
this.Open()
this.Open()
OK
this.Open()
OK
this.ping()
pong
OK
this.Open()
// lorem
OK
^C

@stale stale bot added the stale label Dec 26, 2019
@stale
Copy link

stale bot commented Dec 29, 2019

Due to our very limited maintenance capacity, we need to prioritize our development focus on other tasks. Therefore, this issue will be automatically closed (see #15395 for more details). In the future, if we see the need to attend to this issue again, then it will be reopened. Thank you for your contribution!

@stale stale bot closed this as completed Dec 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants