1

我正在使用wkhtmltoimage. 它适用于例如http://stackoverflow.com

但是当我尝试在任何使用 AngularJs 的网站上运行时(例如https://material.angularjs.org/latest/):

wkhtmltoimage.exe --no-stop-slow-scripts --javascript-delay 5000 --enable-javascript --debug-javascript   https://material.angularjs.org/latest/ C:\\dev\\temp\\0c8fca2c-0990-40c4-8672-12fc71ec6cf6.png

A 得到一个错误 JS 错误(感谢 :--debug-javascript标志)

Loading page (1/2)
Warning: undefined:0 Error: [$injector:modulerr] http://errors.angularjs.org/1.5.5/$injector/modulerr?p0=ng&p1='undefined'%20is%20not%20an%20object
Rendering (2/2)

结果图像只是一个很小的白色条纹。

如何仁

4

1 回答 1

2

似乎 wkhtmltopdf 不能很好地使用Function.prototype.bind(在 Angular >= 1.5 中使用),因此您需要提供一个“polyfill”才能使其正常工作。

Function.prototype.bind = function(oThis) {
    if (typeof this !== 'function') {
        throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
    }

    var aArgs   = Array.prototype.slice.call(arguments, 1),
        fToBind = this,
        fNOP    = function() {},
        fBound  = function() {
            return fToBind.apply(this instanceof fNOP
                ? this
                : oThis,
                aArgs.concat(Array.prototype.slice.call(arguments)));
        };

    if (this.prototype) {
        fNOP.prototype = this.prototype; 
    }

    fBound.prototype = new fNOP();

    return fBound;
};
于 2017-03-20T13:55:39.240 回答