Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minimalcss takes into account css from iframe #331

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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