From d391d48ac3258e1e74ff303d8eb6753167005e58 Mon Sep 17 00:00:00 2001 From: Amit S Namboothiry Date: Sun, 25 Aug 2024 13:23:43 +0530 Subject: [PATCH] Fix prerender js errors --- package-lock.json | 4 ++-- package.json | 2 +- prerender/prerender.js | 12 +++++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index cf693145..55e8c721 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "naadan-chords", - "version": "0.83.0", + "version": "0.83.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "naadan-chords", - "version": "0.83.0", + "version": "0.83.5", "dependencies": { "@fortawesome/fontawesome-svg-core": "^1.2.34", "@fortawesome/free-brands-svg-icons": "^5.15.2", diff --git a/package.json b/package.json index 26bd3aad..0c47ead5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "naadan-chords", - "version": "0.83.0", + "version": "0.83.5", "homepage": "https://www.naadanchords.com/", "private": true, "dependencies": { diff --git a/prerender/prerender.js b/prerender/prerender.js index 6b8d7f68..af90926b 100644 --- a/prerender/prerender.js +++ b/prerender/prerender.js @@ -142,7 +142,17 @@ export async function handler(event) { url.searchParams.append("isPrerendered", true); await page.goto(url.href); - //remove layout breaking ads + // Remove google ads script tags + await page.evaluate(() => { + var elements = document.querySelectorAll("script"); + for (let i = 0; i < elements.length; i++) { + if (elements[i].src.includes("googlesyndication")) { + elements[i].parentNode.removeChild(elements[i]); + } + } + }); + + // remove layout breaking ads let elementClassToRemove = ".ad, .google-auto-placed"; await page.evaluate((sel) => {