Skip to content
Christoph Burgmer edited this page Dec 2, 2013 · 36 revisions
  • Draw a page to the canvas.

    rasterizeHTML.drawURL( url [, canvas] [, options] [, callback] )

  • Draw a HTML string to the canvas.

    rasterizeHTML.drawHTML( html [, canvas] [, options] [, callback] )

  • Draw a Document to the canvas.

    rasterizeHTML.drawDocument( document [, canvas] [, options] [, callback] )

Parameters:

  • url a URL, or
  • html a string of HTML, or
  • document a Document object.

Optional parameters:

  • canvas a HTML5 canvas node
  • options key/value pairs of further options
    • width the width of the image (in 0.7.0: viewport), by default the width of the canvas, or '300' if not provided.
    • height the height of the image (in 0.7.0: viewport), by default the height of the canvas, or '200' if not provided.
    • baseUrl the URL base of the HTML document which relative resources will be based on, default: null.
    • executeJs if set to true, it will execute JavaScript in the page/HTML string and wait for the onload event before drawing the content (not available for drawDocument), default: false.
    • executeJsTimeout will wait the given amount of milliseconds before interrupting the execution of JavaScript. Will also wait if no script is running, default: 0.
    • hover In 0.7.0: a selector whose matched element receives a simulated mouse hover to match :hover style rules, default: null.
    • active In 0.7.0: a selector whose matched element receives a simulated user activation to match :active style rules, default: null.
    • cache allows fine-tuning caching behaviour:
      • 'none' forces requested pages not to be cached by the browser by adding a unique query string in the form of "?_=[timestamp]" to each request,
      • 'repeated' forces a non-cached load for initial calls and caches repeated calls to the same URL,
      • 'all' will not employ any cache busting (default).
    • cacheBucket an object holding the library's own in-memory cache. Only effective in reuse between several calls to the API. Should be initialized with '{}'.
  • callback(image, failedResources) callback function, called when the HTML has been rendered.
    • image the rendered image. In 0.7.0: If content overflows the specified viewport (defined by the width and height parameters or the canvas element's size) the image will have greater dimensions.
    • failedResources a list of resources that failed to load. See below.

Failed resources list

The list of failed resources is returned in the following form: { resourceType: "TYPE_OF_RESOURCE", url: "THE_FAILED_URL", msg: "A_HUMAN_READABLE_MSG" }

Resource types:

  • image an <img href="">
  • stylesheet a <link rel="stylesheet" href="">
  • backgroundImage a background-image: url("");
  • fontFace a @font-face { src: url("") }
  • script a <script src="">
  • scriptExecution a script execution error message (no url specified)
  • document a Document object (general error when the whole Document failed to render, no url specified)
  • page a HTML page (passed to rasterizeHTML.drawURL())

Stability

The library exposes some further methods whose interfaces will not be guaranteed to be stable over time.

Clone this wiki locally