Skip to content

Commit

Permalink
minimalcss takes into account css from iframe
Browse files Browse the repository at this point in the history
Fixes #206
  • Loading branch information
peterbe committed Sep 19, 2019
1 parent 3f21331 commit 2b74c02
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down Expand Up @@ -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') {
Expand Down

0 comments on commit 2b74c02

Please sign in to comment.