From d8002f8ceb53b0ef6d0ee4d94f58876cd4242f2e Mon Sep 17 00:00:00 2001 From: Laurent Goudet Date: Tue, 14 Apr 2020 10:11:35 +0200 Subject: [PATCH 1/2] fix(web): Gracefully degrade Proxy usage to fix IE11 --- core/package.json | 3 ++- core/src/web-runtime.ts | 41 +++++++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/core/package.json b/core/package.json index 264fc4a7c..c7616212f 100644 --- a/core/package.json +++ b/core/package.json @@ -59,7 +59,8 @@ }, "testMatch": [ "**/__test__/*.(ts|tsx|js)" - ] + ], + "testURL": "http://localhost/" }, "dependencies": { "tslib": "^1.9.0" diff --git a/core/src/web-runtime.ts b/core/src/web-runtime.ts index c2f196afe..7c6776762 100644 --- a/core/src/web-runtime.ts +++ b/core/src/web-runtime.ts @@ -10,26 +10,31 @@ export class CapacitorWeb { // get the typed benefits of the provided plugins in PluginRegistry this.Plugins = {} as any; - // Build a proxy for the Plugins object that returns the "Noop Plugin" - // if a plugin isn't available - this.Plugins = new Proxy(this.Plugins, { - get: (target, prop) => { - if (typeof target[prop] === 'undefined') { - let thisRef = this; - return new Proxy({}, { - get: (_target, _prop) => { - if (typeof _target[_prop] === 'undefined') { - return thisRef.pluginMethodNoop.bind(thisRef, _target, _prop, prop); - } else { - return _target[_prop]; + // Gracefully degrade in non-Proxy supporting engines, e.g. IE11. This + // effectively means that trying to access an unavailable plugin will + // locally throw, but this is still better than throwing a syntax error. + if ('Proxy' in window) { + // Build a proxy for the Plugins object that returns the "Noop Plugin" + // if a plugin isn't available + this.Plugins = new Proxy(this.Plugins, { + get: (target, prop) => { + if (typeof target[prop] === 'undefined') { + let thisRef = this; + return new Proxy({}, { + get: (_target, _prop) => { + if (typeof _target[_prop] === 'undefined') { + return thisRef.pluginMethodNoop.bind(thisRef, _target, _prop, prop); + } else { + return _target[_prop]; + } } - } - }); - } else { - return target[prop]; + }); + } else { + return target[prop]; + } } - } - }); + }); + } } pluginMethodNoop(_target: any, _prop: PropertyKey, pluginName: string) { From 6b58239ffe294f05a1fa606b7766b6c697c7d5c8 Mon Sep 17 00:00:00 2001 From: Laurent Goudet Date: Wed, 29 Apr 2020 15:42:00 +0200 Subject: [PATCH 2/2] Revert testURL changes --- core/package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/package.json b/core/package.json index c7616212f..264fc4a7c 100644 --- a/core/package.json +++ b/core/package.json @@ -59,8 +59,7 @@ }, "testMatch": [ "**/__test__/*.(ts|tsx|js)" - ], - "testURL": "http://localhost/" + ] }, "dependencies": { "tslib": "^1.9.0"