Example #1
0
        new Promise(function (resolve, reject) {
          var finalCss = postformatting(stdOut, {
            maxEmbeddedBase64Length: typeof options.maxEmbeddedBase64Length === 'number' ? options.maxEmbeddedBase64Length : DEFAULT_MAX_EMBEDDED_BASE64_LENGTH,
          }, m.DEBUG, START_TIME)

          if (finalCss.trim().length === 0) {
            // TODO: this error should surface to user
            debuglog('Note: Generated critical css was empty for URL: ' + options.url)
          } else {
            // remove irrelevant css properties
            finalCss = apartment(finalCss, {
              properties: [
                '(.*)transition(.*)',
                'cursor',
                'pointer-events',
                '(-webkit-)?tap-highlight-color',
                '(.*)user-select'
              ],
              // TODO: move into core phantomjs script
              selectors: [
                '::(-moz-)?selection'
              ]
            })
          }
          callback(null, finalCss)
          resolve()
          return
        })
Example #2
0
 cp.on('exit', function (code) {
   if (code === 0) {
     if (m.DEBUG) {
       console.log('stdout: ' + stdOut)
       console.log('stderr: ' + stdErr)
     }
     stdOut = removePhantomJSSecurityErrors(stdOut)
     // remove irrelevant css properties
     var finalCss = apartment(stdOut, {
       properties: [
         '(.*)(animation|transition)(.*)',
         'cursor',
         'pointer-events',
         '(-webkit-)?tap-highlight-color',
         '(.*)user-select'
       ],
       // TODO: move into core phantomjs script
       selectors: [
         '::(-moz-)?selection'
       ]
     })
     callback(null, finalCss)
   } else {
     debuggingHelp += 'PhantomJS process exited with code ' + code
     var err = new Error(stdErr + stdOut)
     err.code = code
     err.debug = debuggingHelp
     err.stdout = stdOut
     err.stderr = stdErr
     callback(err)
   }
   // we're done here - clean up
   clearTimeout(killTimeout)
   // can't rely on that the parent process will be terminated any time soon,
   // need to rm listeners and kill child process manually
   process.removeListener('exit', exitHandler)
   process.removeListener('SIGTERM', sigtermHandler)
   cp.kill('SIGTERM')
 })