johntitus/node-horseman

Add support for polyfilling missing PhantomJS JavaScript features

Open

#230 geöffnet am 27. Okt. 2016

Auf GitHub ansehen
 (7 Kommentare) (2 Reaktionen) (0 zugewiesene Personen)JavaScript (134 Forks)batch import
enhancementhelp wanted

Repository-Metriken

Stars
 (1.467 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

PhantomJS does not support some features that websites expect it to. It would be nice for horseman to have built-in support for polyfilling these features.

Here is a way I came up with for polyfilling externally with Polyfill.io, for reference. It is somewhat gross, so if someone comes up with a better way that's great.

var Horseman = require('node-horseman');
var POLYURL = 'https://cdn.polyfill.io/v2/polyfill.min.js';

var horseman = new Horseman();

horseman
    .userAgent()
    .then(function(useragent) { // Get Polyfill based on real UserAgent
        return this.download(POLYURL + '?ua=' + useragent);
    })
    .then(function(polyfill) {
        // Make polyfill into function
        var polyfun = new Function(polyfill);
        // Wrap function in evaluateJavaScript
        var onInit = new Function(
            'console.log("onInitialized");' +
            'page.evaluateJavaScript(' + polyfun.toString() + ')'
        );
        // Call before page loads
        return this.at('initialized', onInit);
    })
    /* Do horseman stuff now */

Assistance/contribution would be greatly appreciated.

Contributor Guide