Skip to content

Commit

Permalink
#13 add a workaround for problematic style sheets causing rendering t…
Browse files Browse the repository at this point in the history
…o fail in FF
  • Loading branch information
tsayen committed Nov 29, 2015
1 parent 7c3224e commit d8f3eb6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dist/dom-to-image.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions spec/dom-to-image.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@
.then(done).catch(error);
});

it('should not crash when loading external stylesheet causes error', function (done) {
loadTestPage('ext-css/dom-node.html', 'ext-css/style.css')
.then(renderToPng)
.then(function(){
done();
})
.catch(error);
});

function compareToControlImage(image, tolerance) {
assert.isTrue(imagediff.equal(image, controlImage(), tolerance), 'rendered and control images should be same');
}
Expand Down
1 change: 1 addition & 0 deletions spec/resources/ext-css/dom-node.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<link href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600" rel="stylesheet">
5 changes: 5 additions & 0 deletions spec/resources/ext-css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#dom-node {
height: 100px;
width: 100px;
background-color: black;
}
6 changes: 5 additions & 1 deletion src/dom-to-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,11 @@
function getCssRules(styleSheets) {
var cssRules = [];
styleSheets.forEach(function (sheet) {
util.asArray(sheet.cssRules || []).forEach(cssRules.push.bind(cssRules));
try {
util.asArray(sheet.cssRules || []).forEach(cssRules.push.bind(cssRules));
} catch (e) {
console.log('Error while reading CSS rules from ' + sheet.href, e.toString());
}
});
return cssRules;
}
Expand Down

0 comments on commit d8f3eb6

Please sign in to comment.