diff --git a/core/src/web-runtime.ts b/core/src/web-runtime.ts index c2f196afe5..7c67767620 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) {