From 0ffa62fab429a90f96df715732fdd671245a180f Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Thu, 13 Aug 2020 20:53:27 +0100 Subject: [PATCH 1/3] fix(*): use fetch polyfill in IE and Edge --- src/SASjs.ts | 13 ++++++++++--- src/utils/isIeOrEdge.ts | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 src/utils/isIeOrEdge.ts diff --git a/src/SASjs.ts b/src/SASjs.ts index 45797b7..28f0fe8 100644 --- a/src/SASjs.ts +++ b/src/SASjs.ts @@ -1,6 +1,10 @@ -import "isomorphic-fetch"; import * as e6p from "es6-promise"; (e6p as any).polyfill(); +if (isIEorEDGE()) { + window.fetch = undefined as any; // ensure the polyfill runs +} +// tslint:disable-next-line +require("isomorphic-fetch"); import { convertToCSV, compareTimestamps, @@ -27,6 +31,7 @@ import { import { SASViyaApiClient } from "./SASViyaApiClient"; import { SAS9ApiClient } from "./SAS9ApiClient"; import { FileUploader } from "./FileUploader"; +import { isIEorEDGE } from "./utils/isIeOrEdge"; const defaultConfig: SASjsConfig = { serverUrl: "", @@ -654,9 +659,11 @@ export default class SASjs { try { responseJson = JSON.parse(response!.result); } catch { - responseJson = JSON.parse(parseWeboutResponse(response!.result)); + responseJson = JSON.parse( + parseWeboutResponse(response!.result) + ); } - + return responseJson; }) .catch(async (e) => { diff --git a/src/utils/isIeOrEdge.ts b/src/utils/isIeOrEdge.ts new file mode 100644 index 0000000..7dc4eea --- /dev/null +++ b/src/utils/isIeOrEdge.ts @@ -0,0 +1,23 @@ +export function isIEorEDGE() { + const ua = window.navigator.userAgent; + + const msie = ua.indexOf("MSIE "); + if (msie > 0) { + // IE 10 or older => return version number + return true; + } + + const trident = ua.indexOf("Trident/"); + if (trident > 0) { + return true; + } + + const edge = ua.indexOf("Edge/"); + if (edge > 0) { + // Edge (IE 12+) => return version number + return true; + } + + // other browser + return false; +} From 870cc0055bb9bcbb9109932e1428bb872416bea8 Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Thu, 13 Aug 2020 21:07:21 +0100 Subject: [PATCH 2/3] fix(*): use fetch polyfill in Firefox 60 --- src/SASjs.ts | 4 ++-- src/utils/isIeOrEdge.ts | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/SASjs.ts b/src/SASjs.ts index 28f0fe8..8ab8daf 100644 --- a/src/SASjs.ts +++ b/src/SASjs.ts @@ -1,6 +1,6 @@ import * as e6p from "es6-promise"; (e6p as any).polyfill(); -if (isIEorEDGE()) { +if (isIEorEdgeOrFirefox60()) { window.fetch = undefined as any; // ensure the polyfill runs } // tslint:disable-next-line @@ -31,7 +31,7 @@ import { import { SASViyaApiClient } from "./SASViyaApiClient"; import { SAS9ApiClient } from "./SAS9ApiClient"; import { FileUploader } from "./FileUploader"; -import { isIEorEDGE } from "./utils/isIeOrEdge"; +import { isIEorEdgeOrFirefox60 } from "./utils/isIeOrEdge"; const defaultConfig: SASjsConfig = { serverUrl: "", diff --git a/src/utils/isIeOrEdge.ts b/src/utils/isIeOrEdge.ts index 7dc4eea..33db0d8 100644 --- a/src/utils/isIeOrEdge.ts +++ b/src/utils/isIeOrEdge.ts @@ -1,6 +1,10 @@ -export function isIEorEDGE() { +export function isIEorEdgeOrFirefox60() { const ua = window.navigator.userAgent; + if (ua.indexOf("Firefox/60") > 0) { + return true; + } + const msie = ua.indexOf("MSIE "); if (msie > 0) { // IE 10 or older => return version number From 59674744be3a2aaed7c03ad4d9b223f1ced672c7 Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Thu, 13 Aug 2020 21:46:08 +0100 Subject: [PATCH 3/3] fix(*): use fetch polyfill for Firefox versions older than 60 --- src/SASjs.ts | 4 ++-- src/utils/isIeOrEdge.ts | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/SASjs.ts b/src/SASjs.ts index 8ab8daf..c78eb3a 100644 --- a/src/SASjs.ts +++ b/src/SASjs.ts @@ -1,6 +1,6 @@ import * as e6p from "es6-promise"; (e6p as any).polyfill(); -if (isIEorEdgeOrFirefox60()) { +if (isIEorEdgeOrOldFirefox()) { window.fetch = undefined as any; // ensure the polyfill runs } // tslint:disable-next-line @@ -31,7 +31,7 @@ import { import { SASViyaApiClient } from "./SASViyaApiClient"; import { SAS9ApiClient } from "./SAS9ApiClient"; import { FileUploader } from "./FileUploader"; -import { isIEorEdgeOrFirefox60 } from "./utils/isIeOrEdge"; +import { isIEorEdgeOrOldFirefox } from "./utils/isIeOrEdge"; const defaultConfig: SASjsConfig = { serverUrl: "", diff --git a/src/utils/isIeOrEdge.ts b/src/utils/isIeOrEdge.ts index 33db0d8..59400da 100644 --- a/src/utils/isIeOrEdge.ts +++ b/src/utils/isIeOrEdge.ts @@ -1,8 +1,12 @@ -export function isIEorEdgeOrFirefox60() { +export function isIEorEdgeOrOldFirefox() { const ua = window.navigator.userAgent; - if (ua.indexOf("Firefox/60") > 0) { - return true; + if (ua.indexOf("Firefox") > 0) { + const version = parseInt( + ua.substring(ua.lastIndexOf("Firefox/") + 8, ua.length), + 10 + ); + return version <= 60; } const msie = ua.indexOf("MSIE ");