2.0.2 • Published 4 months ago

@zippybee/prerender-puppteer v2.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
4 months ago

@zippybee/prerender-puppteer Options

None of the options are required, by default the page will render when puppeteer is ready which is when DOMContentLoaded fires

OptionTypeDefaultDescription
maxConcurrentRoutesNumber0 (No limit)The number of routes allowed to be rendered at the same time. Useful for breaking down massive batches of routes into smaller chunks.
injectObjectNoneAn object to inject into the global scope of the rendered page before it finishes loading. Must be JSON.stringifiy-able. The property injected to is window['__PRERENDER_INJECTED'] by default.
injectPropertyString__PRERENDER_INJECTEDThe property to mount inject to during rendering. Does nothing if inject isn't set.
renderAfterDocumentEventStringDOMContentLoadedWait to render until the specified event is fired on the document. (You can fire an event like so: document.dispatchEvent(new Event('custom-render-trigger'))
renderAfterTimeInteger (Milliseconds)NoneWait to render until a certain amount of time has passed.
renderAfterElementExistsString (Selector)NoneWait to render until the specified element is detected using document.querySelector
elementVisibleBooleanNoneIf we should wait until the renderAfterElementExists is visible
elementHiddenBooleanNoneIf we should wait until the renderAfterElementExists is hidden
timeoutInteger (Milliseconds)30000If this timeout triggers while waiting for an event or an element, the rendering will abort with an error.
skipThirdPartyRequestsBooleanfalseAutomatically block any third-party requests. (This can make your pages load faster by not loading non-essential scripts, styles, or fonts.)
headlessBooleantrueWhether to run the browser in headless mode
consoleHandlerfunction(route: String, message: ConsoleMessage)NoneAllows you to provide a custom console.* handler for pages. Argument one to your function is the route being rendered, argument two is the Puppeteer ConsoleMessage object.
viewportViewportNoneThose options will be passed to puppeteer.launch().
launchOptionsLaunchOptionsNoneThose options will be passed to puppeteer.launch().
navigationOptionsWaitForOptionsNoneThose options will be passed to page.goto(), such as timeout: 30000ms.

Caveats

  • For obvious reasons, prerenderer only works for SPAs that route using the HTML5 history API. index.html#/hash/route URLs will unfortunately not work.
  • Whatever client-side rendering library you're using should be able to at least replace any server-rendered content or diff with it.
    • For Vue.js 1 use replace: false on root components.
    • For Vue.js 2 and 3 Ensure your root component has the same id as the prerendered element it's replacing. Otherwise you'll end up with duplicated content.

Contributing

This is a monorepo, using pnpm, so you'll need to clone the repository, then run pnpm install inside the directory

Run npm run test to make sure that everything is working correctly

Maintainers

2.0.2

4 months ago

2.0.1

4 months ago

2.0.0

4 months ago