@@ -14,7 +14,7 @@ InvalidUrlError.prototype = Error.prototype
1414 * @param {string } waitUntil https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#pagegotourl-options
1515 * @returns {string } All CSS that was found
1616 */
17- module . exports = async ( url , { waitUntil = 'networkidle0' , origins = 'exclude' } = { } ) => {
17+ module . exports = async ( url , { waitUntil = 'networkidle0' , origins = 'exclude' , inlineStyles = 'include' } = { } ) => {
1818 // Setup a browser instance
1919 const browser = await puppeteer . launch ( )
2020
@@ -82,15 +82,18 @@ module.exports = async (url, {waitUntil = 'networkidle0', origins = 'exclude'} =
8282 // CSSRule:
8383 // [x-extract-css-inline-style] { color: red; }
8484 //
85- const inlineCssRules = await page . evaluate ( ( ) => {
86- return [ ...document . querySelectorAll ( '[style]' ) ]
87- . map ( element => element . getAttribute ( 'style' ) )
88- // Filter out empty style="" attributes
89- . filter ( Boolean )
90- } )
91- const inlineCss = inlineCssRules
92- . map ( rule => `[x-extract-css-inline-style] { ${ rule } }` )
93- . map ( css => ( { type : 'inline' , href : url , css} ) )
85+ let inlineCss = [ ]
86+ if ( inlineStyles !== 'exclude' ) {
87+ const inlineCssRules = await page . evaluate ( ( ) => {
88+ return [ ...document . querySelectorAll ( '[style]' ) ]
89+ . map ( element => element . getAttribute ( 'style' ) )
90+ // Filter out empty style="" attributes
91+ . filter ( Boolean )
92+ } )
93+ inlineCss = inlineCssRules
94+ . map ( rule => `[x-extract-css-inline-style] { ${ rule } }` )
95+ . map ( css => ( { type : 'inline' , href : url , css} ) )
96+ }
9497
9598 const links = coverage
9699 // Filter out the <style> tags that were found in the coverage
@@ -108,7 +111,7 @@ module.exports = async (url, {waitUntil = 'networkidle0', origins = 'exclude'} =
108111
109112 const css = links
110113 . concat ( styleSheetsApiCss )
111- . concat ( inlineCss )
114+ . concat ( inlineStyles === 'exclude' ? [ ] : inlineCss )
112115
113116 // Return the complete structure ...
114117 if ( origins === 'include' ) {
0 commit comments