New issue
Advanced search Search tips

Issue 732052 link

Starred by 7 users

Issue metadata

Status: Archived
Owner: ----
Closed: Jun 2018
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux
Pri: 2
Type: Bug



Sign in to add a comment

--stdout flag to allow headless mode to send screenshot or print-to-pdf output to stdout

Reported by sgorn...@digicoast.com, Jun 10 2017

Issue description

UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/60.0.3112.24 Chrome/60.0.3112.24 Safari/537.36

Steps to reproduce the problem:
Want to pipe output of screenshot image when chromium isin headless mode to ImageMagick's display utility, for example.

1. $ chromium-browser --headless --disable-gpu --screenshot --stdout https://www.chromestatus.com/ | display -

What is the expected behavior?
If a --stdout flag existed for headless mode chromium-browser, I would expect the ImageMagick display utility to create a window with the contents of the image that was piped to its stdin.

What went wrong?
logged output on stderr:

[0610/104005.309881:INFO:headless_shell.cc(464)] Written to file screenshot.png.

Which, is the documented behavior because there is no --stdout.

Did this work before? N/A 

Chrome version: 60.0.3112.24  Channel: beta
OS Version: 60.0.3112.24
Flash Version: 

I'ld like to use the screenshot output from chromium-browser in a shell script so want the headless mode's output on stdout so I can pipe it to another command.  

For example, the display utility from ImageMagick optionally takes stdin as input allowing me to do the following:

$ display test.png | display -

If chromium-browser were to optionally generate output to stdout  (rather than writing it to a file), I could then use it in the same manner.  So this is a feature request -- something that could be implemented simply with something like a --stdout flag:

This would improve Chrome's utility for use in scripting, particularly where permission to write to the filesystem is restricted (e.g., on a web server).

There are currently two argument that generate output, --screenshot  and --print-to-pdf, so I suppose adding something like --stdout would need to apply to both of those usages that generate output.   I see some other utilities (e.g., bzip2) use a --stdout flag, whereas others (e.g., tar) use other variations including one of either -O or --to-stdout as the flag, so just wanted to share how other utilities handle optionally directing output ot stdout with a flag.
 
Correction to the line 

$ display test.png | display -

Should have been:

$ cat test.png | display -

This was initially placed as a question on the Chrome product help forum:

- https://productforums.google.com/forum/#!topic/chrome/W_1Cf31TTjw
Labels: Needs-Triage-M60
Components: Internals>Headless
Labels: TE-NeedsTriageHelp
The issue seems to be out of TE-scope. Hence, adding label TE-NeedsTriageHelp for further investigation.

Thanks...!!
Adding a use case here.

Our application includes a calendar that agencies print and give to elderly clients who are more accustomed to physical paper than digital calendars. To generate this paper calendar, our customers click a Print icon.

Ideally, the server flow when the Print icon is clicked would look something like this:
  - Node generates the "print" HTML for the calendar
  - Node creates a child process for chrome --headless --print-to-pdf, piping HTML in on stdin
  - Node pipes chrome --headless stdout directly to the HTML response
  - Browser downloads a PDF

Without the ability to read from stdin and write to stdout, the flow is much more complicated:
  - Node generates the "print" HTML for the calendar, storing it in memory
  - Node creates a temp URL so a request from chrome --headless can access the generated HTML
  - Node creates a temp file for chrome --headless output
  - Node creates a child process for chrome --headless with a URL like http://localhost/temp123 and a temp filename
  - Chrome calls the temp URL, reads HTML, and writes to the temp file
  - Node pipes the file contents to the HTML response
  - Browser downloads a PDF
  - Node deletes the temp file and invalidates the temp URL

stdin and stdout would greatly simplify this process.
> chris.va...@gmail.com
> Adding a use case here.

I believe the DATA URI scheme already gives you the ability to load a page from Stdin.

$ cat test.html|chromium-browser "data:text/html;charset=utf-8,$(< /dev/stdin)"

Or, for it to be secure, convert it to base64 first:

$ cat test.html|base64|chromium-browser "data:text/html;charset=utf-8;base64,$(< /dev/stdin)"

Maybe even just URLEncode it instead of base64 would work, I'm not sure.
The base64 strategy is working great! That solves the stdin challenge.

I agree with the original poster though -- I would rather not need to enable FS write permissions on my web server to enable this use case, and a --stdout flag would fit my need perfectly.
> The base64 strategy is working great! That solves the stdin challenge.

It's kind of a hack.  I now see that Chromium imposes a limit on the size for data: (of 2MB ?):

- https://craignicol.wordpress.com/2016/07/19/excellent-export-and-the-chrome-url-limit/
- https://bugs.chromium.org/p/chromium/issues/detail?id=69227

Perhaps blob: instead of data: could be used which doesn't have the limit?

Or just have --headless accept the html on stdin if neither a file+path nor a URI was passed as an argument.   Or when in headless mode could explicitly specify to load from stdin with a  --stdin switch, or an -i switch even, or anything like that.

So yes, essentially this feature request is for support of both stdin and stdout.

stdin: for the contents of the resource to load
and
stdout: for the png or pdf output
Scratch my comment about the stdin challenge being solved. We easily ran into the limit on medium-sized datasets. For now, we will be using the temp URL strategy, in the hopes that we can replace it with a simpler stdin- and stdout-based strategy soon =)
Project Member

Comment 10 by sheriffbot@chromium.org, Jun 27 2018

Status: Archived (was: Unconfirmed)
Issue has not been modified or commented on in the last 365 days, please re-open or file a new bug if this is still an issue.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot

Sign in to add a comment