From 9bcd84b5b8e4c3b8c23279d632d5f81ca638fec5 Mon Sep 17 00:00:00 2001 From: Fran Rouco Date: Thu, 17 Oct 2024 20:20:07 +0200 Subject: [PATCH] Hide iframe content feature --- README.md | 1 + examples/backstop.json | 6 ++++++ setup.js | 17 +++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/README.md b/README.md index 310bae9..ebbd228 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,5 @@ A library that extends the default functionality of BackstopJS. - Login and navigate to a specific page - Wait for selector after interaction - Custom user agent by viewport +- Hide iframes content diff --git a/examples/backstop.json b/examples/backstop.json index 3cec4dc..552dd34 100644 --- a/examples/backstop.json +++ b/examples/backstop.json @@ -49,6 +49,12 @@ "loginUser": "user name to override the global one", "loginPass": "password to override the global one", "loginRedirectTo": "page_url/to/go/after/login" + }, + { + "label": "Hide iframe content example", + "url": "http://something.com/page-url", + "readySelector": "body", + "hideIframeContent": ".iframe-container-selector, .iframe-container-selector-2" } ], "paths": { diff --git a/setup.js b/setup.js index b0a8806..13cf9ef 100644 --- a/setup.js +++ b/setup.js @@ -29,6 +29,23 @@ module.exports = async (page, scenario, config) => { }, scenario); } + // Hide iframe content. + if (scenario.hideIframeContent) { + await page.evaluate(async(scenario) => { + const iframeContainers = document.querySelectorAll(scenario.hideIframeContent); + + iframeContainers.forEach((iframeContainer) => { + const iframe = iframeContainer.querySelector('iframe'); + if (iframe) { + iframe.src = ''; + iframe.style.background = "lightgray"; + iframeContainer.style.position = 'relative'; + iframeContainer.innerHTML += '
Iframe
'; + } + }); + }, scenario); + } + // Common actions await page.evaluate(async(config) => { // Avoid lazy css load.