Skip to content

Commit fb774bc

Browse files
committed
try catch
1 parent 026f435 commit fb774bc

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/utils/helpers.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,18 @@ const utils = {
102102
getCanonicalUrl: () => {
103103
let canonicalURL = null;
104104

105-
if (utils.canUseDOM()) {
106-
const linkEle = document?.querySelector('link[rel="canonical"]');
107-
const href = linkEle?.getAttribute('href');
105+
try {
106+
if (utils.canUseDOM()) {
107+
const linkEle = document?.querySelector('link[rel="canonical"]');
108+
const href = linkEle?.getAttribute('href');
108109

109-
if (href) {
110-
const url = new URL(href, document.location.href);
111-
canonicalURL = url.toString();
110+
if (href) {
111+
const url = new URL(href, document.location.href);
112+
canonicalURL = url.toString();
113+
}
112114
}
115+
} catch (e) {
116+
// do nothing
113117
}
114118

115119
return canonicalURL;

0 commit comments

Comments
 (0)