Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(web): Gracefully degrade Proxy usage to fix IE11 #2759

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions core/src/web-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>(this.Plugins, {
get: (target, prop) => {
if (typeof target[prop] === 'undefined') {
let thisRef = this;
return new Proxy<any>({}, {
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<any>(this.Plugins, {
get: (target, prop) => {
if (typeof target[prop] === 'undefined') {
let thisRef = this;
return new Proxy<any>({}, {
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) {
Expand Down