{"action":"opened","issue":{"url":"https://api.github.com/repos/johntitus/node-horseman/issues/158","repository_url":"https://api.github.com/repos/johntitus/node-horseman","labels_url":"https://api.github.com/repos/johntitus/node-horseman/issues/158/labels{/name}","comments_url":"https://api.github.com/repos/johntitus/node-horseman/issues/158/comments","events_url":"https://api.github.com/repos/johntitus/node-horseman/issues/158/events","html_url":"https://github.com/johntitus/node-horseman/issues/158","id":147788260,"number":158,"title":"Bluebird promise library not found","user":{"login":"winghouchan","id":6061021,"avatar_url":"https://avatars.githubusercontent.com/u/6061021?v=3","gravatar_id":"","url":"https://api.github.com/users/winghouchan","html_url":"https://github.com/winghouchan","followers_url":"https://api.github.com/users/winghouchan/followers","following_url":"https://api.github.com/users/winghouchan/following{/other_user}","gists_url":"https://api.github.com/users/winghouchan/gists{/gist_id}","starred_url":"https://api.github.com/users/winghouchan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/winghouchan/subscriptions","organizations_url":"https://api.github.com/users/winghouchan/orgs","repos_url":"https://api.github.com/users/winghouchan/repos","events_url":"https://api.github.com/users/winghouchan/events{/privacy}","received_events_url":"https://api.github.com/users/winghouchan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-04-12T15:32:15Z","updated_at":"2016-04-12T15:32:15Z","closed_at":null,"body":"I'm attempting to use the built-in promise library, however it can't seem to be found when running a function being evaluated in the browser. Here's a simplified case:\r\n\r\n```javascript\r\nconst debug = require('debug')('test');\r\nconst config = { 'injectBluebird': true, 'bluebirdDebug': true, };\r\nconst Horseman = require('node-horseman');\r\nconst horseman = new Horseman(config);\r\n\r\nhorseman\r\n  .on('consoleMessage', function (msg) {\r\n    debug(msg);\r\n  })\r\n  .userAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.4.10 (KHTML, like Gecko) Version/8.0.4 Safari/600.4.10')\r\n  .open('https://google.com')\r\n  .evaluate(function () {\r\n    console.log(typeof Promise);\r\n    console.log(typeof P);\r\n    console.log(typeof Bluebird);\r\n  })\r\n  .close();\r\n```\r\n\r\nThe output is:\r\n\r\n```\r\n  horseman using PhantomJS from $PATH +0ms\r\n  horseman .setup() creating phantom instance on 12406 +6ms\r\n  horseman phantom created +524ms\r\n  horseman phantom version 2.0.0 +19ms\r\n  horseman page created +10ms\r\n  horseman phantomjs onLoadFinished triggered +10ms success NaN\r\n  horseman injected jQuery +31ms\r\n  horseman injected bluebird +8ms\r\n  horseman:verbose onError +5ms ReferenceError: Can't find variable: Promise\r\n\tphantomjs://webpage.evaluate(): 4 in configBluebird\r\n\tphantomjs://webpage.evaluate(): 9 in <anonymous> 12406\r\n  horseman .on() consoleMessage set. +7ms\r\n  horseman .userAgent() set +22ms Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.4.10 (KHTML, like Gecko) Version/8.0.4 Safari/600.4.10\r\n  horseman .open() +1ms https://google.com\r\n  horseman phantomjs onLoadFinished triggered +767ms success 1\r\n  horseman injected jQuery +16ms\r\n  horseman injected bluebird +11ms\r\n  horseman:verbose onError +4ms ReferenceError: Can't find variable: Promise\r\n\tphantomjs://webpage.evaluate(): 4 in configBluebird\r\n\tphantomjs://webpage.evaluate(): 9 in <anonymous> 12406\r\n  horseman .evaluate() +4ms <anonymous>\r\n  test undefined +10ms\r\n  test undefined +0ms\r\n  horseman:verbose .evaluate() finished synchronously +1ms <anonymous> s 12406\r\n  horseman .close(). +5ms\r\n```\r\nFrom [Horseman documentation](https://github.com/johntitus/node-horseman#evaluatefn-arg1-arg2\r\n), it seems I should access Bluebird via `Bluebird`.\r\n\r\n> Lastly, if `fn` returns a Promise or thenable, it will be waited on and the action in Node will resolve/reject accordingly.\r\n\r\n```javascript\r\nhorseman\r\n  .open('http://en.wikipedia.org/wiki/Headless_Horseman')\r\n  .evaluate(function() {\r\n    // Silly example for illustrative purposes.\r\n    return Bluebird.delay(100).return('Hello World');\r\n  })\r\n  .then(function(mesg){\r\n    // Will log 'Hello World' after a roughly 100 ms delay.\r\n    console.log(mesg);\r\n  })\r\n  .close();\r\n```\r\n\r\nFrom [Bluebird documentation](http://bluebirdjs.com/docs/getting-started.html), it seems I should access Bluebird via `Promise` or `P`.\r\n\r\n> When using script tags the global variables `Promise` and `P` (alias for `Promise`) become available."}}