I am using AngularJS built on top of Node/Express for a Web application. One of my routes has an HTML5 canvas that I convert to an image. If I traverse to that route with this, I have no issues with converting my canvas to an image:
when('/myroute/, { templateUrl: 'views/mytemplate.html', controller: 'myCtrl as vm' })
However, when I use dynamic routing (since I need to pass a unique ID to the 'myroute' page), the Canvas to image conversion throws the following error:
Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
Here is the dynamic route syntax from my App.js:
when('/myroute/:ID, { templateUrl: 'views/mytemplate.html', controller: 'myCtrl as vm' })
Why would a dynamic route cause this... what appears to be a CORS issue, and how do I resolve it? Could it be related to "living" on top of Node.js/Express?
Here is an example of how I convert the Canvas to an Image:
var canvasImage = document.getElementById("c");
var img = canvasImage.toDataURL("image/png");
Update 1: I just tried the following, but received the same error:
var canvasImage = document.getElementById("c");
var img = new Image();
img.crossOrigin = "anonymous";
img.src = canvasImage;
img = canvasImage.toDataURL("image/png");
Update 2: After digging deeper, I discovered that it is my overlay that causes the actual error since the overly image comes from a remote server. That remote server has CORS enabled. What is really odd is still my main issue. It works in a standard route, but fails in a dynamic route!