Skip to content


Subversion checkout URL

You can clone with
Download ZIP
PHP Proxy html2canvas
Failed to load latest commit information.
examples Create usable-example.html Update
html2canvasproxy.php Update html2canvasproxy.php

html2canvas-php-proxy 0.1.11

PHP Proxy html2canvas

This script allows you to use html2canvas.js with different servers, ports and protocols (http, https), preventing to occur "tainted" when exporting the <canvas> for image.

Others scripting language

You do not use PHP, but need html2canvas working with proxy, see other proxies:

Problem and Solution

When adding an image that belongs to another domain in <canvas> and after that try to export the canvas for a new image, a security error occurs (actually occurs is a security lock), which can return the error:

SecurityError: DOM Exception 18

Error: An attempt was made to break through the security policy of the user agent.


I ask you to follow me or "star" my repository to track updates

Run script in Cross-domain (data URI scheme)

(See details:

Note: Enable cross-domain in proxy server can consume more memory, but can be faster in execution it performs only one request at the proxy server.

Note: If the file html2canvasproxy.php is in the same domain that your project, you do not need to enable this option.

Note: Disable the "cross-domain" does not mean you will not be able to capture images from different servers, in other words, the "cross-domain" here refers to "html2canvas.js" (not necessarily the javascript file, but the place where runs) and the "html2canvas.php" are in different domains, the "cross-domain" here refers domain.

In some cases you may want to use this html2canvasproxy.php on a specific server, but the "html2canvas.js" and another server, this would cause problems in your project with the security causing failures in execution. In order to use security just set in the html2canvasproxy.php:

Enable cross-domain in proxy server:

define('CROSS_DOMAIN', 1);

Disable cross-domain in proxy server:

define('CROSS_DOMAIN', 0);


Note: Requires PHP 4.3.0+

<!DOCTYPE html>
        <meta charset="utf-8">
        <title>html2canvas php proxy</title>
        <script src="html2canvas.js"></script>
        (function() {
            window.onload = function(){
                html2canvas(document.body, {
                    "logging": true, //Enable log (use Web Console for get Errors and Warnings)
                    "onrendered": function(canvas) {
                        var img = new Image();
                        img.onload = function() {
                            img.onload = null;
                        img.onerror = function() {
                            img.onerror = null;
                            if(window.console.log) {
                                window.console.log("Not loaded image from canvas.toDataURL");
                            } else {
                                alert("Not loaded image from canvas.toDataURL");
                        img.src = canvas.toDataURL("image/png");
            <img alt="google maps static" src=",-73.998672&amp;zoom=12&amp;size=800x600&amp;maptype=roadmap&amp;sensor=false">

Using Web Console

If you have any problems with the script recommend to analyze the log use the Web Console from your browser:

Get NetWork results:

An alternative is to diagnose problems accessing the link directly:


Replace [DOMAIN] by your domain (eg. and replace [PATH] by your project folder (eg. project-1/test), something like:



Changelog moved to

Next version

Details of future versions are being studied, in other words, can happen as can be forsaken ideas. The ideas here are not ready or are not public in the main script, are only suggestions. You can offer suggestions on issues.

  • Etag cache browser for use HTTP 304 (resources are reusable, avoiding unnecessary downloads)
  • Cache from SOCKET, if not specified header cache in SOCKET, then uses settings by DEFINE();
Something went wrong with that request. Please try again.