Giter Club home page Giter Club logo

portal's Introduction

Portal

Docker

Portal is a headless Chrome rendering solution designed to render & serialise web pages for use by agents

This repo is a fork of Rendertron, upgraded to support the latest versions of puppeteer, chrome-stable, and container deployments.

Built with

๐Ÿค– Puppeteer โ€ข ๐Ÿ“ Typescript โ€ข ๐Ÿšข Docker

Portal renders requested pages using Headless Chrome, auto-detecting when your PWA has completed loading and serializes the response back to the original request. To use portal, your application configures middleware to determine whether to proxy a request to portal. Portal is compatible with all client side technologies, including web components.


Demo endpoint

A demo portal service is available at https://portal.stuntdouble.io. It is not designed to be used as a production endpoint. You can use it, but there are no uptime guarantees.

Contents

Middleware

Once you have the service up and running, you'll need to implement the differential serving layer. This checks the user agent to determine whether prerendering is required.

This is a list of middleware available to use with the portal service:

Portal is also compatible with prerender middleware. Note: the user agent lists differ there.

API

Render

GET /render/<url>

The render endpoint will render your page and serialize your page. Options are specified as query parameters:

  • mobile defaults to false.
  • ?mobile appended will request the mobile version.

Screenshot

GET /screenshot/<url>
POST /screenshot/<url>

The screenshot endpoint can be used to verify that your page is rendering correctly.

Both endpoints support the following query parameters:

  • width defaults to 1000 - specifies viewport width.
  • height defaults to 1000 - specifies viewport height.
  • mobile defaults to false. Enable by passing ?mobile to request the mobile version of your site.

Additional options are available as a JSON string in the POST body. See Puppeteer documentation for available options. You cannot specify the type (defaults to jpeg) and encoding (defaults to binary) parameters.

FAQ

Query parameters

When setting query parameters as part of your URL, ensure they are encoded correctly. In JS, this would be encodeURIComponent(myURLWithParams). For example to specify page=home:

https://portal.stuntdouble.io/render/http://my.domain/%3Fpage%3Dhome

Auto detecting loading function

The service detects when a page has loaded by looking at the page load event, ensuring there are no outstanding network requests and that the page has had ample time to render.

Rendering budget timeout

There is a hard limit of 10 seconds for rendering. Ensure you don't hit this budget by ensuring your application is rendered well before the budget expires.

Web components

Headless Chrome supports web components but shadow DOM is difficult to serialize effectively. As such, shady DOM (a lightweight shim for Shadow DOM) is required for web components.

If you are using web components v0 (deprecated), you will need to enable Shady DOM to render correctly. In Polymer 1.x, which uses web components v0, Shady DOM is enabled by default. If you are using Shadow DOM, override this by setting the query parameter dom=shady when directing requests to the portal service.

If you are using web components v1 and either webcomponents-lite.js or webcomponents-loader.js, set the query parameter wc-inject-shadydom=true when directing requests to the portal service. This renderer service will force the necessary polyfills to be loaded and enabled.

Status codes

Status codes from the initial requested URL are preserved. If this is a 200, or 304, you can set the HTTP status returned by the rendering service by adding a meta tag.

<meta name="render:status_code" content="404" />

Running locally

To install puppeteer and run it locally, first install puppeteer:

npm install -g puppeteer

Installing & deploying

Building

Clone and install dependencies:

git clone https://github.com/turnout-labs/portal.git
cd portal
npm install
npm run build

Running locally

With a local instance of Chrome installed, you can start the server locally:

npm run start

Building docker image

The indcluded docker file builds a version with chrome-stable bundled in the install process. Accepts PORT as an env variable to adjust the listening port. See https://render.com/docs/deploy-puppeteer-node/

docker build . -t turnout-labs/portal

Config

When deploying the service, set configuration variables by including a config.json in the root. Available configuration options:

  • datastoreCache default false - set to true to enable caching on Google Cloud using datastore
  • timeout default 10000 - set the timeout used to render the target page.
  • port default 3000 - set the port to use for running and listening the portal service. Note if process.env.PORT is set, it will be used instead.
  • width default 1000 - set the width (resolution) to be used for rendering the page.
  • height default 1000 - set the height (resolution) to be used for rendering the page.

Troubleshooting

If you're having troubles with getting Headless Chrome to run in your environment, refer to the troubleshooting guide for Puppeteer.

portal's People

Contributors

samuelli avatar aomarks avatar mrprkr avatar avgp avatar abdonrd avatar gravi2 avatar anurag avatar keanulee avatar rajikaimal avatar danielpoonwj avatar frankiefu avatar justinribeiro avatar lesterchan avatar sindorei1993 avatar piperchester avatar ramadimasatria avatar rofrol avatar samthor avatar gregurco avatar a335926a avatar retanoj avatar

Stargazers

 avatar

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.