From 3323377fb8846782b16b5ec2962e5347b2995d38 Mon Sep 17 00:00:00 2001 From: Khaja Nizamuddin Date: Wed, 18 Apr 2018 05:19:29 +0530 Subject: [PATCH] handled js cookie errors when cookies are not available. --- src/assets/embed/ana-web-chat-plugin.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/assets/embed/ana-web-chat-plugin.js b/src/assets/embed/ana-web-chat-plugin.js index 3793f93..972e33e 100644 --- a/src/assets/embed/ana-web-chat-plugin.js +++ b/src/assets/embed/ana-web-chat-plugin.js @@ -15,14 +15,21 @@ }; }, setCookie: (name, value, days = 7, path = '/') => { - const expires = new Date(Date.now() + days * 864e5).toUTCString() - document.cookie = name + '=' + encodeURIComponent(value) + '; expires=' + expires + '; path=' + path + try { + const expires = new Date(Date.now() + days * 864e5).toUTCString() + document.cookie = name + '=' + encodeURIComponent(value) + '; expires=' + expires + '; path=' + path + } catch (e) { + } }, getCookie: (name) => { - return document.cookie.split('; ').reduce((r, v) => { - const parts = v.split('=') - return parts[0] === name ? decodeURIComponent(parts[1]) : r - }, '') + try { + return document.cookie.split('; ').reduce((r, v) => { + const parts = v.split('=') + return parts[0] === name ? decodeURIComponent(parts[1]) : r + }, '') + } catch (e) { + return ''; + } }, deleteCookie: (name, path) => { setCookie(name, '', -1, path)