Live data from Hacker News

Headless mode in Firefox

developer.mozilla.org

161–170 of 191 posts

Re: Headless mode in Firefox

#161
post #17
post #6

Can you tell Firefox to print in headless mode? I want to write reports using HTML and JS, but printing is always an issue.

You can generate pdfs with headless Chromium/Chrome pretty easily[1]. chromium-browser --headless --disable-gpu --print-to-pdf=output_file_name.pdf file:///path/to/your/html [1] https://developers.google.com/web/updates/2017/04/headless-c...

Any idea when exactly the PDF capture is performed? So many pages now render a minimal initial load, while the actual content is greatly delayed (usually Capturing the PDF at even the onload event (let alone the useless DOMContentLoaded event) is going to capture an incomplete picture in a huge number of situations. Frankly, a PDF capture at onload event is going to be utterly unusable. Is there a way to set a delay before capturing, ie: 10 seconds?

In an ideal world, a true "finished loading" event would trigger only after all DOMContentLoaded and onload handlers are executed, only once any AJAX requests launched by such handlers are completed (including requests fired off in their handlers, recursively). Of course, websockets and long polling ajax would still interfere with detecting a true "finished" event, but it'd be better than setting an artificially large delay of 10+ seconds.

Re: Headless mode in Firefox

#162
post #15

Earlier quoted context omitted.

A small nomenclature clarification seems to be in order: "Headless" means without output. It is often used to describe servers without any attached monitors (the monitor would be the head that it is missing), but can similarly be used to describe browsers that do not even create a window on your desktop. It simply runs as a service that can be scripted. What you are looking for, I would rather call "chromeless". The…

> What you are looking for, I would rather call "chromeless". The browser is there, but it has no visible UI-components outside of the webpage. Why "chromless" and not just "Full screen"? The latter is what that mode has been known by for decades? Or is it a subtle distinction that "Full screen" mode can show the location bar by moving the mouse to that edge of the screen (at least in Firefox 55), while "chromless" n…

Those are two orthogonal concerns. A (theoretical) browser in full screen mode might or might not display UI elements/browser chrome. A windowed browser might or might not display browser chrome.

A chromeless windowed browser would look something like QuickTime in macOS, if that helps you; the window consists entirely of the playing video until you mouse over it.

Re: Headless mode in Firefox

#165

The article mentions screenshots. I am interested in running the browser as a rendering tool, but ouputing not just a bitmap, but something closer to PDF. The goal here would be to crawl a bunch of pages and spin up the CPU to run all the needed JavaScript to render things, but to obtain an identical version of the page that runs about as fast viewing a screenshot, but also includes text. An offline "web OCR", if you…

I'm pretty sure you could write some WebDriver + JavaScript that captures the DOM/text in the page. You might even be able to capture layout information for later reconstruction.

Re: Headless mode in Firefox

#166
post #145

Earlier quoted context omitted.

What are the features that make Prince XML better than headless chrome? Prince XML is not open source or cheap.

PrinceXML is in a league of it's own. Very, very light weight. Very fast and it has outstanding output. The price tag is steep for sure, but if your business relies on PDF output then nothing comes close.

Do you use it in the context of technical documentation? Does it make using Docbook a bearable experience?

Re: Headless mode in Firefox

#167
post #61

Now if only Firefox also implemented the Chrome Remote Debugging Protocol... https://chromedevtools.github.io/debugger-protocol-viewer/to...

Mozilla DevTools is exploring implementing parts of the Chrome DevTools Protocol ("CDP") in Firefox. https://groups.google.com/forum/#!topic/mozilla.dev.platform...

Re: Headless mode in Firefox

#168

The article mentions screenshots. I am interested in running the browser as a rendering tool, but ouputing not just a bitmap, but something closer to PDF. The goal here would be to crawl a bunch of pages and spin up the CPU to run all the needed JavaScript to render things, but to obtain an identical version of the page that runs about as fast viewing a screenshot, but also includes text. An offline "web OCR", if you…

I'm pretty sure you could write some WebDriver + JavaScript that captures the DOM/text in the page. You might even be able to capture layout information for later reconstruction.

That's useful to know, thank you. Perhaps the solution isn't so complicated.

Re: Headless mode in Firefox

#169

Earlier quoted context omitted.

Just set your browser to always show punycode. On Firefox, network.IDN_show_punycode = true URLs are no place for unicode characters to hide in. An xn-- prefix is all the warning you need.

Your claims are false for the majority of the world's population (which lives in non-English speaking countries and may well want to visit sites whose names make sense in their own language).

That's why Firefox detects if the URL mixes together symbols from different languages:

https://wiki.mozilla.org/IDN_Display_Algorithm

Much better than showing punycode all the time.

Re: Headless mode in Firefox

#170

Earlier quoted context omitted.

I highly recommend that anyone using a headless browser that may access outside sources employ something like this to run the headless browser in an external environment, in this case AWS Lambda: https://github.com/justengland/phantom-lambda-template I used this approach for a project at a previous company and not only did it keep the potentially unsafe external code execution isolated from the rest of the stack, but…

That's a neat approach, I'm not on anything like that scale though, looking for something to get rid of JasperReports.

Did you find any library that implements this? I mean, it should not be hard to implement, just slap together some templating language like thymeleaf or velocity and shell it to the headless browser. But still, it would be nice to have all this already implemented.
Post reply on HN