From 2b74c029e151392ca2a952c94e0bd048b3a4c9e4 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Thu, 19 Sep 2019 16:24:42 -0400 Subject: [PATCH] minimalcss takes into account css from iframe Fixes #206 --- src/run.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/run.js b/src/run.js index 942e208c..b34a8594 100644 --- a/src/run.js +++ b/src/run.js @@ -127,7 +127,7 @@ const processStylesheet = ({ if (value.type !== 'Raw') { path = path.substr(1, path.length - 2); } - const sameHost = url.parse(responseUrl).host === url.parse(pageUrl).host; + const sameHost = isSameHost(responseUrl, pageUrl); if (/^https?:\/\/|^\/\/|^data:/i.test(path)) { // do nothing } else if (/^\//.test(path) && sameHost) { @@ -150,6 +150,10 @@ const processStylesheet = ({ stylesheetContents[responseUrl] = text; }; +const isSameHost = (url1, url2) => { + return url.parse(url1).host === url.parse(url2).host; +}; + const processPage = ({ page, options, @@ -221,7 +225,11 @@ const processPage = ({ page.on('request', request => { const resourceType = request.resourceType(); const requestUrl = request.url(); - if (/data:image\//.test(requestUrl)) { + if (resourceType === 'document' && !isSameHost(requestUrl, pageUrl)) { + // Iframes within the document are resourceType==='document' and + // don't want to consider its internal stylesheets. + request.abort(); + } else if (/data:image\//.test(requestUrl)) { // don't need to download those request.abort(); } else if (!loadimages && resourceType === 'image') {