diff --git a/build/html2canvas.js b/build/html2canvas.js index 16b0117..7ad1759 100644 --- a/build/html2canvas.js +++ b/build/html2canvas.js @@ -8,22 +8,25 @@ (function(window, document, undefined){ window.html2canvas = function(nodeList, options) { - var container = createWindowClone(document, window.innerWidth, window.innerHeight); - var clonedWindow = container.contentWindow; - var element = (nodeList === undefined) ? document.body : nodeList[0]; - var node = clonedWindow.document.documentElement; - var support = new Support(); - var imageLoader = new ImageLoader(options, support); options = options || {}; if (options.logging) { window.html2canvas.logging = true; window.html2canvas.start = Date.now(); } + createWindowClone(document, window.innerWidth, window.innerHeight).then(function(container) { + log("Document cloned"); + var clonedWindow = container.contentWindow; + var element = (nodeList === undefined) ? document.body : nodeList[0]; + var node = clonedWindow.document.documentElement; + var support = new Support(); + var imageLoader = new ImageLoader(options, support); - var renderer = new CanvasRenderer(documentWidth(), documentHeight(), imageLoader); - var parser = new NodeParser(node, renderer, support, imageLoader, options); - window.console.log(parser); + var renderer = new CanvasRenderer(documentWidth(), documentHeight(), imageLoader); + var parser = new NodeParser(node, renderer, support, imageLoader, options); + + window.console.log(parser); + }); }; function documentWidth () { @@ -50,13 +53,38 @@ function createWindowClone(ownerDocument, width, height) { container.style.position = "absolute"; container.style.width = width + "px"; container.style.height = height + "px"; - ownerDocument.body.appendChild(container); - var documentClone = container.contentWindow.document; - documentClone.replaceChild(documentClone.adoptNode(documentElement), documentClone.documentElement); + return new Promise(function(resolve) { + var loadedTimer = function() { + /* Chrome doesn't detect relative background-images assigned in style sheets when fetched through getComputedStyle, + before a certain time has passed + */ + if (container.contentWindow.getComputedStyle(div, null)['backgroundImage'] !== "none") { + documentClone.body.removeChild(div); + documentClone.body.removeChild(style); + resolve(container); + } else { + window.setTimeout(loadedTimer, 10); + } + }; + var documentClone = container.contentWindow.document; + /* Chrome doesn't detect relative background-images assigned in inline