From f8a4a2c510a08c246ac957ac71d86ff5e86ffdb0 Mon Sep 17 00:00:00 2001 From: Dennis Schubert Date: Fri, 13 Jul 2018 00:04:41 +0200 Subject: [PATCH] Gracefully ignore exceptions when trying to register the ProtocolHandler --- .../javascripts/helpers/protocol_handler.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/helpers/protocol_handler.js b/app/assets/javascripts/helpers/protocol_handler.js index 6d9368979..c857c1b51 100644 --- a/app/assets/javascripts/helpers/protocol_handler.js +++ b/app/assets/javascripts/helpers/protocol_handler.js @@ -2,19 +2,20 @@ Diaspora.ProtocolHandler = { register: function() { - if (typeof (window.navigator.registerProtocolHandler) !== "function") { + if (!window.navigator.registerProtocolHandler) { return false; } - var protocol = location.protocol; - var slashes = protocol.concat("//"); - var host = slashes.concat(window.location.hostname); - - if (location.port) { - host = host.concat(":" + location.port); + try { + window.navigator.registerProtocolHandler( + "web+diaspora", + [window.location.protocol, "//", window.location.host, "/link?q=%s"].join(""), + document.title + ); + } catch (_) { + return false; } - window.navigator.registerProtocolHandler("web+diaspora", host.concat("/link?q=%s"), document.title); return true; } };