From c3925f02a6ad3d898539fbe3a75016a573cf0d40 Mon Sep 17 00:00:00 2001 From: Aleksandra Timofejeva <aleksandra.timofejeva@Tilde.lv> Date: Thu, 8 Aug 2024 17:05:31 +0300 Subject: [PATCH 1/2] null check for head tag --- src/js/lib/SearchEngineOptimization.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/js/lib/SearchEngineOptimization.ts b/src/js/lib/SearchEngineOptimization.ts index 2e8bcf4..716444e 100644 --- a/src/js/lib/SearchEngineOptimization.ts +++ b/src/js/lib/SearchEngineOptimization.ts @@ -84,8 +84,10 @@ export class SearchEngineOptimization { let link = doc.querySelector('link[rel="canonical"]') as HTMLLinkElement if (!link) { link = document.createElement('link') - doc.head.appendChild(link) - link.rel = 'canonical' + if (doc.head !== null) { + doc.head.appendChild(link) + link.rel = 'canonical' + } } if (restore) { if (link.hasAttribute(ORIGINAL_URL_ATTR)) { From 6e6ca80b2640300bd608da7029a83b7ed88e3c2e Mon Sep 17 00:00:00 2001 From: Aleksandra Timofejeva <aleksandra.timofejeva@Tilde.lv> Date: Thu, 8 Aug 2024 17:11:22 +0300 Subject: [PATCH 2/2] comment fix --- src/js/lib/SearchEngineOptimization.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/js/lib/SearchEngineOptimization.ts b/src/js/lib/SearchEngineOptimization.ts index 716444e..2823c97 100644 --- a/src/js/lib/SearchEngineOptimization.ts +++ b/src/js/lib/SearchEngineOptimization.ts @@ -82,12 +82,10 @@ export class SearchEngineOptimization { private markCanonicalUrl (doc: Document, currentLocale: string, restore = false) { let link = doc.querySelector('link[rel="canonical"]') as HTMLLinkElement - if (!link) { + if (!link && doc.head !== null) { link = document.createElement('link') - if (doc.head !== null) { - doc.head.appendChild(link) - link.rel = 'canonical' - } + doc.head.appendChild(link) + link.rel = 'canonical' } if (restore) { if (link.hasAttribute(ORIGINAL_URL_ATTR)) {