File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -177,6 +177,24 @@ export function drawImageInCanvas(img) {
177177 return canvas ;
178178}
179179
180+ /**
181+ * Detect IOS device
182+ * see: https://stackoverflow.com/a/9039885
183+ * @returns {boolean } isIOS device
184+ */
185+ function isIOS ( ) {
186+ return [
187+ 'iPad Simulator' ,
188+ 'iPhone Simulator' ,
189+ 'iPod Simulator' ,
190+ 'iPad' ,
191+ 'iPhone' ,
192+ 'iPod' ,
193+ ] . includes ( navigator . platform )
194+ // iPad on iOS 13 detection
195+ || ( navigator . userAgent . includes ( 'Mac' ) && 'ontouchend' in document ) ;
196+ }
197+
180198/**
181199 * drawFileInCanvas
182200 *
@@ -186,6 +204,9 @@ export function drawImageInCanvas(img) {
186204export async function drawFileInCanvas ( file ) {
187205 let img ;
188206 try {
207+ if ( isIOS ( ) ) {
208+ throw new Error ( 'Skip createImageBitmap on IOS device' ) ; // see https://github.com/Donaldcwl/browser-image-compression/issues/118
209+ }
189210 img = await createImageBitmap ( file ) ;
190211 } catch ( e ) {
191212 const dataUrl = await getDataUrlFromFile ( file ) ;
You can’t perform that action at this time.
0 commit comments