From a0958cfde4f8152cf0aa5a5ba1cb7b1416e53d0b Mon Sep 17 00:00:00 2001 From: Moumita Date: Mon, 18 Jul 2022 12:10:06 +0530 Subject: [PATCH 1/5] added error handling for dead obj accessing error --- utils/utils.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/utils/utils.js b/utils/utils.js index 6dd423c80..23b3e4320 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -193,7 +193,12 @@ function getDefaultPageProperties() { } function getReferrer() { - return document.referrer || "$direct"; + // This error handling is in place to avoid accessing dead object(document) + try { + return document.referrer || "$direct"; + } catch(e){ + return "$direct"; + } } function getReferringDomain(referrer) { From 30c23dc944f045d704ac6aed4efdf39131715dbd Mon Sep 17 00:00:00 2001 From: Moumita <36885121+MoumitaM@users.noreply.github.com> Date: Mon, 18 Jul 2022 18:39:20 +0530 Subject: [PATCH 2/5] Update utils/utils.js Co-authored-by: Sai Kumar Battinoju <88789928+saikumarrs@users.noreply.github.com> --- utils/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/utils.js b/utils/utils.js index 23b3e4320..bab50c183 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -196,7 +196,7 @@ function getReferrer() { // This error handling is in place to avoid accessing dead object(document) try { return document.referrer || "$direct"; - } catch(e){ + } catch(e) { return "$direct"; } } From 11dd65220aafaacc00d8c9b45f0c6b2c7a262f82 Mon Sep 17 00:00:00 2001 From: Moumita Date: Mon, 18 Jul 2022 20:36:04 +0530 Subject: [PATCH 3/5] code refactoring --- utils/utils.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/utils/utils.js b/utils/utils.js index bab50c183..4727bac09 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -194,10 +194,12 @@ function getDefaultPageProperties() { function getReferrer() { // This error handling is in place to avoid accessing dead object(document) + const referrer = "$direct"; try { - return document.referrer || "$direct"; - } catch(e) { - return "$direct"; + return document.referrer || referrer; + } catch (e) { + logger.error(e); + return referrer; } } From 4418e3dd7296ab3044a6438afa6ed5dd02c4c6c5 Mon Sep 17 00:00:00 2001 From: Moumita <36885121+MoumitaM@users.noreply.github.com> Date: Mon, 18 Jul 2022 23:43:28 +0530 Subject: [PATCH 4/5] Update utils/utils.js Co-authored-by: Sai Kumar Battinoju <88789928+saikumarrs@users.noreply.github.com> --- utils/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/utils.js b/utils/utils.js index 4727bac09..fa2c187cf 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -194,7 +194,7 @@ function getDefaultPageProperties() { function getReferrer() { // This error handling is in place to avoid accessing dead object(document) - const referrer = "$direct"; + const defaultReferrer = "$direct"; try { return document.referrer || referrer; } catch (e) { From 3b0d3acd9f995a1f2dc0ebf1929791a43426e2c3 Mon Sep 17 00:00:00 2001 From: Moumita <36885121+MoumitaM@users.noreply.github.com> Date: Mon, 18 Jul 2022 23:43:58 +0530 Subject: [PATCH 5/5] Update utils/utils.js Co-authored-by: Sai Kumar Battinoju <88789928+saikumarrs@users.noreply.github.com> --- utils/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/utils.js b/utils/utils.js index fa2c187cf..273c97171 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -198,7 +198,7 @@ function getReferrer() { try { return document.referrer || referrer; } catch (e) { - logger.error(e); + logger.error("Error trying to access 'document.referrer': ", e); return referrer; } }