less.js icon indicating copy to clipboard operation
less.js copied to clipboard

Phantom can not parse LESS

Open roelvanduijnhoven opened this issue 12 years ago • 14 comments

I am using webshot to try to generate a screenshot of a website that is compiling LESS on the client machine. However this fails. webshot uses Phantom.js as an underlying mechanism.

For example when I target this Fiddle http://jsfiddle.net/Yhcz4/23/ I get the following Phantom error in the initFunctions function (when I remove this line other unrelated errors pop up)

TypeError: 'undefined' is not a function (evaluating '_math.bind(null, Math[f], mathFunctions[f])')

What am I doing wrong. Or is Phantom JS simply not able to work with Less.js?

roelvanduijnhoven avatar Mar 27 '14 09:03 roelvanduijnhoven

We auto test using phantomjs so I'm not sure what is going wrong. Is it a later version of phantom?

lukeapage avatar Mar 27 '14 12:03 lukeapage

I use version 1.9.7-1 that is resolved via webshot.

└─┬ [email protected]
  ├─┬ [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├─┬ [email protected]
  │ │ ├─┬ [email protected]
  │ │ │ └── [email protected]
  │ │ ├── [email protected]
  │ │ ├── [email protected]
  │ │ ├─┬ [email protected]
  │ │ │ └── [email protected]
  │ │ ├── [email protected]
  │ │ ├── [email protected]
  │ │ └── [email protected]
  │ ├── [email protected]
  │ └── [email protected]
  └── [email protected]

The script to replicate is the following. That yields an image where CSS has NOT been applied.

var webshot = require('webshot');
webshot('http://jsfiddle.net/Yhcz4/23/embedded/result/', 'test.jpg', function() {});

roelvanduijnhoven avatar Mar 27 '14 13:03 roelvanduijnhoven

Sorry I don't know. All I know is less is compatible with phantom - I use 1.7, but I can't see that being the issue.

I don't know how webshot works, but does it wait for the page to be initialised before taking a screenshot?

Sorry but I think you'll have to debug yourself. Please let us know if there is anything we are doing that is incompatible with an environment that should be changed.

lukeapage avatar Apr 01 '14 12:04 lukeapage

I ran into the exact same bug today and it seems to be related to this issue: https://github.com/ariya/phantomjs/issues/10522

tl; dr: the Webkit version used by PhantomJS is missing the Function.prototype.bind implementation.

I suppose this is not triggered while testing less using PhantomJS simply because the initFunctions() function is not tested, and it is the only one using bind().

This seems to work for me: https://github.com/ariya/phantomjs/issues/10522#issuecomment-16125397

clementgarnier avatar Apr 02 '14 19:04 clementgarnier

I suppose this is not triggered while testing less using PhantomJS simply because the initFunctions() function is not tested,

Nope, look at its sources closer: initFunctions initializes 20 built-in functions and they are all tested.

seven-phases-max avatar Apr 02 '14 19:04 seven-phases-max

My mistake. There seems to be a compatibility script in the project that fixes the PhantomJS bug mentioned above: https://github.com/less/less.js/blob/master/test/browser/es5.js

clementgarnier avatar Apr 02 '14 20:04 clementgarnier

Are you also using webshot?

Op woensdag 2 april 2014 heeft Clément Garnier [email protected] het volgende geschreven:

My mistake. There seems to be a compatibility script in the project that fixes the PhantomJS bug mentioned above: https://github.com/less/less.js/blob/master/test/browser/es5.js

Reply to this email directly or view it on GitHubhttps://github.com/less/less.js/issues/1938#issuecomment-39376930 .

roelvanduijnhoven avatar Apr 02 '14 20:04 roelvanduijnhoven

No, I'm using a jasmine test runner that uses PhantomJS behind the scenes.

clementgarnier avatar Apr 02 '14 21:04 clementgarnier

https://github.com/less/less.js/blob/master/test/browser/es5.js

:)

seven-phases-max avatar Apr 03 '14 01:04 seven-phases-max

Allright, but that then explains why Less is not running out-of-the-box on Phantom right? The snipplet mentioned is namely only included in testing mode. I concatenated the es5.js file to the start of the Less library and after that is works correctly!

Now the question remains: is this known/acceptable behaviour?

roelvanduijnhoven avatar Apr 03 '14 06:04 roelvanduijnhoven

Yes.. Less requires a modern browser to run. We should add this info to less-docs. I'll add a note in the browser compatability section on the website.

lukeapage avatar Apr 11 '14 06:04 lukeapage

https://github.com/less/less-docs/commit/d357fd34124697fc57f0a6b5f454f58062132dd9

lukeapage avatar Apr 11 '14 06:04 lukeapage

@lukeapage Thats for the document update. Could you also please provide an example of what that shim might look like for those of us newer to Steal, etc.?

RALifeCoach avatar Jan 21 '16 15:01 RALifeCoach

@RALifeCoach

Could you also please provide an example of what that shim might look like

It's a "standard" ES5 polyfill script: es-5 shim (The link is right in the doc section @lukeapage pointed to).

seven-phases-max avatar Jan 22 '16 04:01 seven-phases-max