PhantomJS node with external scripts
<p>I've written a phantomjs script using node to take screenshots of a webpage. The page I'm trying to screenshot includes an important external script which adds variables to the global window object. ie. window.__components.</p>

<p>The problem is, this is never set. It works fine in a browser but it just dies in phantomJS. I've altered the script to inject the script before opening the page, I've added a check to make sure that the components object has been added before opening the page and still it fails.</p>

<p>Any ideas?</p>

<pre><code>function injectExternalScripts(page, ph, url) {
    page.includeJs('http://external-script', ()=&gt;{

        page.evaluate(() =&gt; {
            return window;
        }, function(result) {
            if(result.__components) {
                openPage(page, ph, url);
            }
        });

    });
}

function openPage(page, ph, url) {
    page.open(url, (status)=&gt;{
        // errors returned from page 
        // window.__components is null
    });
}
</code></pre>