1

I'm using PhantomJS to generate a series of images based on the state of an HTML canvas element which I am manipulating via JS. This canvas manipulation depends on 3 separate JS libraries and some inline scripts which I invoke during window.onload.

The PhantomJS docs cover how to include a single JS library, but it doesn't cover how to include several.

Can anyone provide me with the correct syntax to include several JS libs, and then run some scripts during window.onload?

1
  • For the time being I am concatenating all my JS dependencies into a single file to get around this, but I'd rather not if a proper solution is available. Commented Jun 15, 2015 at 8:01

1 Answer 1

5

There is a callback for page.includeJs(). When the first one is done, then you can load the next one. This is usually done recursively.

function multipleIncludeJs(page, jsArray, done) {
    if (jsArray.length === 0) {
        done();
        return;
    }

    var url = jsArray.shift();
    page.includeJs(url, function(){
        multipleIncludeJs(page, jsArray, done);
    });
}

and use it like this:

multipleIncludeJs(page, ["http://code.jquery...", "http://getbootstrap..."], function(){
    console.log("loaded");
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.