Giter VIP home page Giter VIP logo

puppetron's Introduction

Puppetron

Puppeteer (Headless Chrome Node API)-based rendering solution.

Videos & Tweets:

⚠️⚠️⚠️ NOTE: Starting version 2.0, CJK and emoji support is gone.

🚧🚧🚧 PLEASE READ THIS 🚧🚧🚧

Do NOT use this for production use-cases.

This is just a demo site of what cool things that Puppeteer can do. Under any circumstances, this site may be down any time or be heavily rate-limited to prevent abuse.

Please check out what Puppeteer can do for your own use case and host on your own servers.

API

The API can perform 3 actions:

  • Screenshot - take a screenshot of the web page
  • Render - render and serialize a HTML copy of the web page
  • PDF - generate a PDF of the web page

URL - the URL with encoded pathname, search and hash.

Global parameters:

  • width - width of viewport/screenshot (default: 1024)
  • height - height of viewport/screenshot (default: 768)

Screenshot

/screenshot/{URL}
...or
/{URL}

Parameters:

  • thumbWidth - width of thumbnail, respecting aspect ratio (no default, has to be smaller than width)
  • fullPage - takes a screenshot of the full scrollable page (default: false). If the page is too long, it may time out.
  • clipSelector - CSS selector of element to be clipped (no default). E.g.: .weather-forecast.

Render

/render/{URL}

Notes:

  • script tags except JSON-LD will be removed
  • link[rel=import] tags will be removed
  • HTML comments will be removed
  • base tag will be added for loading relative resources
  • Elements with absolute paths like src="/xxx" or href="/xxx" will be prepended with the origin URL.

Parameters: None

PDF

/pdf/{URL}

Parameters:

  • format: Paper format that Puppeteer supports. E.g.: Letter, Legal, A4, etc. (default: Letter)
  • pageRanges: Paper ranges to print. E.g., 1-5, 8, 11-13 (default all pages)

Development

Requirements

Steps

  1. npm i
  2. npm start
  3. Load localhost:3000

Credits

Block list from Prerender.

For version 1.0, this uses cheeaun/puppeteer Docker image.

For version 2.0, this uses some parts from Zeit's now-examples: misc-screenshot.

Inspired by zenato/puppeteer, puppeteer-renderer and Rendertron.

puppetron's People

Contributors

cheeaun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

puppetron's Issues

How to use clipSelector for screenshot

How to use clipSelector for screenshot?

This works just fine:
https://puppetron.now.sh/screenshot/http://www.xe.com/currencycharts/%3Ffrom%3DUSD%26to%3DCAD%26view%3D1D?width=500&height=900

However, after adding &clipSelector=div.module.clearfix to the end of it, it is no longer working:

https://puppetron.now.sh/screenshot/http://www.xe.com/currencycharts/%3Ffrom%3DUSD%26to%3DCAD%26view%3D1D?width=500&height=900&clipSelector=div.module.clearfix

I got:

Oops. Something is wrong.

Protocol error (Emulation.setDeviceMetricsOverride): Invalid parameters height: integer value expected

Is it a bug?

Returns result too fast causing titles not to be updated.

Am trying out your solution to see if it is a good fit for our solution. We have a PWA build that fetches some information from our GraphQL backend. The page I'm trying to load fires the DOM-loaded event very early. This causes issues as the page is actually still loading some information..

Docker file?

Great demo site... I would like to set up a local copy using docker, but although you mention docker, I cannot see a docker build file or reference to a prefabricated image. Or am I blind?
Thanks, Joachim

Ready for production, if self-hosted?

Hello @cheeaun, and thank you so much for building this, I was trying to do the same thing with puppeteer.

I saw with pleasure the it can render perfectly my Polymer application without problems, unlike rendertron with whom I have some problems.

I'm wondering if puppetron could be production-ready if I will host my self in a production environment. What do you think? Does it need known improvements about the implementation?

lost port numbers

When not running on port 80 we encountered a problem where the port number (ex: 8080) was getting dropped and therefore suggest some thing like:

   const path = decodeURIComponent(pathname);

   await new Promise((resolve, reject) => {
       const req = http.request({
           method: 'HEAD',
           port: port,
           host: hostname,
           path,
       }, ({statusCode, headers}) => {```
instead of 
const {origin, hostname, pathname, searchParams} = new URL(url);
const path = decodeURIComponent(pathname);

await new Promise((resolve, reject) => {
    const req = http.request({
        method: 'HEAD',
        host: hostname,
        path,
    }, ({statusCode, headers}) => {
        if (!headers || (statusCode == 200 && !/text\/html/i.test(headers['content-type']))) {
    reject(new Error('Not a HTML page'));```

ironically, I don't have easy access to port 80 so haven't tested this much yet, but thought I would raise the issue.

cheers,
Mark

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.