You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In #7 I proposed sharing Blobs. The primary use case for this is sharing images, but using this API to share images is a bit hard. If you wanted to share the contents of a <canvas> you would do:
varcanvas;// HTMLCanvasElement representing a <canvas> elementcanvas.toBlob(blob=>navigator.share({blob: blob,mimeType: 'image/png'}),'image/png');
A little unwieldy, but manageable.
To share an <img> element, things get a bit hairy:
varimage;// HTMLImageElement representing an <img> elementvarcanvas=document.createElement('canvas');canvas.width=image.width;canvas.height=image.height;canvas.getContext('2d').drawImage(image,0,0);canvas.toBlob(blob=>navigator.share({blob: blob,mimeType: 'image/png'}),'image/png');
(Note: I haven't tested this code, just wrote it on the fly. There may be an easier way but that's the best way I can find to convert an image into a blob.)
So maybe we should be providing a share attribute called 'image' that takes a CanvasImageSource -- basically lets you directly share an Image, Video or Canvas object without having to convert to a blob. The usage would be:
varimage;// HTMLImageElement representing an <img> elementnavigator.share({image: image,mimeType: 'image/png'}),
As shown above, this isn't strictly necessary (can be polyfilled). So it would be a policy decision whether we want to provide unnecessary-but-helpful abstractions, or whether we should save that for wrapper libraries.
marsjaninzmarsa, vitalh, thewarpaint, kawerewagaba, kotborealis and 10 more