From 41dd1a6a741e0eb8209bd324eb849ffba4008c9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 15 Oct 2020 17:07:37 +0200 Subject: [PATCH] MOBILE-3565 utils: Fix copy to clipboard on browser --- src/app/services/utils/utils.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/app/services/utils/utils.ts b/src/app/services/utils/utils.ts index e48f2493f..eb77397e0 100644 --- a/src/app/services/utils/utils.ts +++ b/src/app/services/utils/utils.ts @@ -308,12 +308,17 @@ export class CoreUtilsProvider { async copyToClipboard(text: string): Promise { try { await Clipboard.instance.copy(text); - - // Show toast using ionicLoading. - CoreDomUtils.instance.showToast('core.copiedtoclipboard', true); } catch { - // Ignore errors. + // Use HTML Copy command. + const virtualInput = document.createElement('textarea'); + virtualInput.innerHTML = text; + virtualInput.select(); + virtualInput.setSelectionRange(0, 99999); + document.execCommand('copy'); } + + // Show toast using ionicLoading. + CoreDomUtils.instance.showToast('core.copiedtoclipboard', true); } /**