Closed
Description
I got Event error when I run it on Safari 8.0.7
OOOOOOOPS, something went wrong!
Event
bubbles: false
cancelBubble: false
cancelable: false
clipboardData: undefined
currentTarget: null
defaultPrevented: false
eventPhase: 0
returnValue: true
srcElement: null
target: null
timeStamp: 1459283334222
type: "error"
__proto__: EventPrototype
the function I ran is like the following
function () {
domtoimage.toPng(document.querySelector('body'))
.then(function (dataUrl) {
var img = new Image();
img.src = dataUrl;
document.body.appendChild(img);
})
.catch(function (error) {
console.error('OOOOOOOOPS, something went wrong!', error);
});
}
Activity
tsayen commentedon Mar 30, 2016
Unfortunately I don't have access to Safari. Can you at least share complete example via, say, jsfiddle?
nsonnad commentedon Apr 12, 2016
In Safari 9.1, I get
on
toPng
, however thetoSvg
function appears to work finetsayen commentedon Apr 24, 2016
@nsonnad your problem might be that some resources you're trying to render are loaded from different domain, that makes it impossible to read rendered data back from the canvas that the library uses internally (see MDN). Do you think that would be the case?
kirilledelman commentedon Apr 26, 2016
@tsayen Is this the same problem I'm experiencing in Firefox?
No error in Chrome though.
My page imports google fonts - and I get
Error while reading CSS rules from https://fonts.googleapis.com/css?family=Roboto:300,400,400italic,500,700,700italic,900" SecurityError: The operation is insecure.
error while rendering.tsayen commentedon Apr 26, 2016
@kirilledelman I think your issue is the same as #13
evianzhow commentedon Oct 11, 2016
Hi tsayen. I've been developing a functionality similar to this repo and meet the same problem.
toDataURL()
in Chrome Desktop works fine but failed in Safari Mobile and Desktop.Pseudo code is like this:
Canvas is generated by html2canvas and not tainted by cross-origin images.
I googled about this and find nothing useful. Do you have any clue?
bsautel commentedon Nov 10, 2016
In Cordova iOS I am also getting this event error.
After investigation, it appears that it is thrown by
onerror
in this code:When this error occurs, the
src
attribute value is:data:image/svg+xml,base64,
. The URL that was previously in thesrc
attribute couldn't be resolved (byget || util.getAndEncode
) probably because of a security restriction and thesrc
attribute has an invalid value. It is the reason why theonerror
handler is called with the associated event.Note that I get this behavior only in a Cordova context and not when using Safari over HTTP. In Cordova, all resources are embedded in the application and served through
file:///
.When I test the same code served by HTTP I get the
SecurityError: DOM Exception 18
error.I keep investigating to understand why I don't get the same behavior.
sarath-sasikumar commentedon Feb 8, 2017
The reason for the SecurityError is the canvas getting tainted in Safari.
When the
canvas.toDataURL()
is applied on a tainted canvas, the Security error is encounteredApparently in Safari whenever a
<foreignObject>
is encountered inside a canvas, it gets taintedAs the canvas is drawn with this foreignObject the origin-clean flag is set to false and the canvas is hence being shown to be tainted. From a tainted canvas when the toDataURl function is called the Security Error is encountered.
https://html.spec.whatwg.org/multipage/scripting.html#security-with-canvas-elements
sarath-sasikumar commentedon May 19, 2017
@tsayen Do you have any opinion regarding how this issue may be addressed
Any workarounds!!!
alexmakeev commentedon May 29, 2017
+1
also have same issue, BTW, I had same code better working with html2canvas lib (no security error gotten)
thiphariel commentedon Apr 2, 2019
Don't know if it's fixed since then, but I tried this package on Safari 12.0 (MacOS Mojave 10.14) and it's working perfectly. My tag img is nicely created with no glitch or something else :)
Just to let you know
kkevindev commentedon Apr 19, 2019
Works perfectly on Safari 12.1 (macOS Mojave 10.14.4)
HarshaKomalla1 commentedon Apr 30, 2019
Still facing the issue in Safari 12.1. Any workarounds??
rubenmelchers commentedon Oct 30, 2020
I managed to successfully create PNG on safari 14.0 (on both desktop & iOS), which came out last september! I hope I'm not the only one.
obedparla commentedon Jun 9, 2021
According to caniuse and MDN, safari now supports
foreignObject
.I confirm it works on Safari 14.0.3
kkevindev commentedon Jul 9, 2021
Safari supports
foreignObject
since 18th March of 2008, way back when Safari 3 was a thing. Also, Safari 12.1 already works (#27 (comment))siddiquekhanonism commentedon Oct 17, 2022
Can you please let us know how you solve the problem, so that we can check and fix the problem in our end.