Sketchfab Forum

getScreenShot in Edge


(Charper) #1

getScreenShot in edge is opening a new window without any contents. This works in Chrome, Firefox, and Opera without problem. Here is the code

api.start(function () {
	$("#screenshot").click(function () {
		api.getScreenShot("image/png", function (err, result) {
			var height = $("#model-iframe").height();
			var width = $("#model-iframe").width();
			if (height < 100) {
				height = 100;
			}
			if (width > 100) {
				width = 100;
			}
			window.open(result, "_blank");
		});
	});
});

(Paul Sketch) #2

"result" is a URL encoded image and thus prone to URL length hard limits that depends on browsers vendors implementations

You can try to either:
- use jpeg
- a smaller image by using a smaller sketchfab iframe (gives smaller url encoded)
- use blob/createdataURL if you need png and support any resolution (see http://stackoverflow.com/questions/32217537/windows-edge-and-opening-a-blob-url && http://stackoverflow.com/questions/12168909/blob-from-dataurl)


(Charper) #3

Thanks! I had no idea that would be an issue with Edge. I've tried to implement that blob approach. It works fine in Chrome and Firefox, but Edge is returning a "SCRIPT5: Access is denied." when I execute window.open(). Any ideas? Could Edge think the blob is cross-domain?
Here's the code that's being passed the data uri and opening the window:

                            var byteString = atob(result.split(',')[1]);
                            var mimeString = result.split(',')[0].split(':')[1].split(';')[0]
                            var ab = new ArrayBuffer(byteString.length);
                            var ia = new Uint8Array(ab);
                            for (var i = 0; i < byteString.length; i++) {
                                ia[i] = byteString.charCodeAt(i);
                            }

                            var blob = new Blob([ab], { type: mimeString });
                            var url = URL.createObjectURL(blob);
                            window.open(url);

(Paul Sketch) #4

from http://stackoverflow.com/questions/27463901/setting-window-location-or-window-open-in-angularjs-gives-access-is-denied-in seems the anwser might be

if (window.navigator && window.navigator.msSaveOrOpenBlob) {
    window.navigator.msSaveOrOpenBlob(blob);
}
else {
    var objectUrl = URL.createObjectURL(blob);
    window.open(objectUrl);
}

(Charper) #5

Thanks! Works perfectly!