pocketjoso / penthouse

Generate critical css for your web pages
https://jonassebastianohlsson.com/criticalpathcssgenerator
MIT License
2.63k stars 165 forks source link

Suppress errors from phantomjs? #58

Closed bitinn closed 9 years ago

bitinn commented 9 years ago

I sometimes see these lines in the output css when running penthouse, is there any way to prevent phantomjs from messing with output?

Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///Users/local/git/mai/node_modules/penthouse/lib/phantomjs/core.js. Domains, protocols and ports must match.

my command look something like this:

penthouse https://local.dev/ public/app.css --width 1366 --height 768 > public/inline.css
fatso83 commented 9 years ago

Can you make this into a reproducible case? I would like to look at it when given the time, but make it easy for me and it will be sooner rather than later ;-)

bitinn commented 9 years ago

I am ok with investigating this myself, I am following leads on this 2 threads:

https://github.com/ariya/phantomjs/issues/12697 https://github.com/n1k0/casperjs/issues/1068

I believe either:

  1. adding webSecurityEnabled: false to your phantomjs config.json (I tried and it works). ref
  2. wrap all phantom.exit in setTimeout to discard these stdout warnings. ref
  3. the cause for this error is due to phantoms 1.9.x changing url on exit and triggers CSP, this issue does not exist on 2.x, so upgrading penthouse support to phantomjs 2.x also works.

From this PR discussion I believe the issue won't be fixed on 1.9.x branch

https://github.com/ariya/phantomjs/pull/12720

Solution for fix 1 and 2 are relatively simple, if you prefer I can make a PR

bitinn commented 9 years ago

PS: yet another alternative is to downgrade to phantomjs: 1.9.11 (the nodejs wrapper module) which is the last wrapper to use phantomjs 1.9.7, which doesn't have this problem (last release is 1.9.8).

Which direction would you prefer?

pocketjoso commented 9 years ago

@bitinn From my quick readup on this problem upgrading phantomjs to 2.x should solve the problem. The only reason I haven't is because of lack of official Linux release, so if you're on a non Linux platform, I would suggest upgrading.

As for a fix for this release, I should be able to supress the error from within Penthouse. If you solve it before me, good, otherwise will look into this weekend.

Cheers

pocketjoso commented 9 years ago

Should be resolved now - please reopen if you still see issues.

pocketjoso commented 9 years ago

The solution implemented only suppresses errors thrown on exit, but there are other types of errors we also don't want, like:

Unsafe JavaScript attempt to access frame with..

I'l look into how to handle this properly.