From b175ed21d06e6d6b7efde8ddbe9d20498c4618bb Mon Sep 17 00:00:00 2001 From: "Ashley (Scirra)" Date: Fri, 26 Apr 2019 13:51:39 +0100 Subject: [PATCH] Fix navigator.share polyfill breaking Web Share L2 The Web Share API L2 allows for sharing files, but SocialSharing.js unconditionally overwrites navigator.share with an L1 implementation which does not support sharing files. Only polyfill if navigator.share is not defined, removing the possibility of overwriting an L2 implementation with L1. --- www/SocialSharing.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/www/SocialSharing.js b/www/SocialSharing.js index 0dbc9f77..ae222cc0 100644 --- a/www/SocialSharing.js +++ b/www/SocialSharing.js @@ -137,7 +137,12 @@ SocialSharing.install = function () { } window.plugins.socialsharing = new SocialSharing(); - navigator.share = window.plugins.socialsharing.shareW3C; + + // Note only polyfill navigator.share if it is not defined, since shareW3C implements L1 of the spec, + // and an existing navigator.share method could implement L2. + if (!navigator.share) + navigator.share = window.plugins.socialsharing.shareW3C; + return window.plugins.socialsharing; };