Phantom can not parse LESS
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?
We auto test using phantomjs so I'm not sure what is going wrong. Is it a later version of phantom?
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() {});
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.
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
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.
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
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 .
No, I'm using a jasmine test runner that uses PhantomJS behind the scenes.
https://github.com/less/less.js/blob/master/test/browser/es5.js
:)
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?
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.
https://github.com/less/less-docs/commit/d357fd34124697fc57f0a6b5f454f58062132dd9
@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
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).