@@ -14,7 +14,7 @@ InvalidUrlError.prototype = Error.prototype
14
14
* @param {string } waitUntil https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#pagegotourl-options
15
15
* @returns {string } All CSS that was found
16
16
*/
17
- module . exports = async ( url , { waitUntil = 'networkidle0' , origins = 'exclude' } = { } ) => {
17
+ module . exports = async ( url , { waitUntil = 'networkidle0' , origins = 'exclude' , inlineStyles = 'include' } = { } ) => {
18
18
// Setup a browser instance
19
19
const browser = await puppeteer . launch ( )
20
20
@@ -82,15 +82,18 @@ module.exports = async (url, {waitUntil = 'networkidle0', origins = 'exclude'} =
82
82
// CSSRule:
83
83
// [x-extract-css-inline-style] { color: red; }
84
84
//
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
+ }
94
97
95
98
const links = coverage
96
99
// Filter out the <style> tags that were found in the coverage
@@ -108,7 +111,7 @@ module.exports = async (url, {waitUntil = 'networkidle0', origins = 'exclude'} =
108
111
109
112
const css = links
110
113
. concat ( styleSheetsApiCss )
111
- . concat ( inlineCss )
114
+ . concat ( inlineStyles === 'exclude' ? [ ] : inlineCss )
112
115
113
116
// Return the complete structure ...
114
117
if ( origins === 'include' ) {
0 commit comments