Bluebird promise library not found
See original GitHub issueI’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:
const debug = require('debug')('test');
const config = { 'injectBluebird': true, 'bluebirdDebug': true, };
const Horseman = require('node-horseman');
const horseman = new Horseman(config);
horseman
.on('consoleMessage', function (msg) {
debug(msg);
})
.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')
.open('https://google.com')
.evaluate(function () {
console.log(typeof Promise);
console.log(typeof P);
console.log(typeof Bluebird);
})
.close();
The output is:
horseman using PhantomJS from $PATH +0ms
horseman .setup() creating phantom instance on 12406 +6ms
horseman phantom created +524ms
horseman phantom version 2.0.0 +19ms
horseman page created +10ms
horseman phantomjs onLoadFinished triggered +10ms success NaN
horseman injected jQuery +31ms
horseman injected bluebird +8ms
horseman:verbose onError +5ms ReferenceError: Can't find variable: Promise
phantomjs://webpage.evaluate(): 4 in configBluebird
phantomjs://webpage.evaluate(): 9 in <anonymous> 12406
horseman .on() consoleMessage set. +7ms
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
horseman .open() +1ms https://google.com
horseman phantomjs onLoadFinished triggered +767ms success 1
horseman injected jQuery +16ms
horseman injected bluebird +11ms
horseman:verbose onError +4ms ReferenceError: Can't find variable: Promise
phantomjs://webpage.evaluate(): 4 in configBluebird
phantomjs://webpage.evaluate(): 9 in <anonymous> 12406
horseman .evaluate() +4ms <anonymous>
test undefined +10ms
test undefined +0ms
horseman:verbose .evaluate() finished synchronously +1ms <anonymous> s 12406
horseman .close(). +5ms
From Horseman documentation, it seems I should access Bluebird via Bluebird
.
Lastly, if
fn
returns a Promise or thenable, it will be waited on and the action in Node will resolve/reject accordingly.
horseman
.open('http://en.wikipedia.org/wiki/Headless_Horseman')
.evaluate(function() {
// Silly example for illustrative purposes.
return Bluebird.delay(100).return('Hello World');
})
.then(function(mesg){
// Will log 'Hello World' after a roughly 100 ms delay.
console.log(mesg);
})
.close();
From Bluebird documentation, it seems I should access Bluebird via Promise
or P
.
When using script tags the global variables
Promise
andP
(alias forPromise
) become available.
Issue Analytics
- State:
- Created 7 years ago
- Comments:12
Top Results From Across the Web
Installation - Bluebird.js
Bluebird is a fully featured JavaScript promises library with unmatched performance.
Read more >Error Explanations - Bluebird JS
A promise is a process, it starts and it ends. Promises do not aim to solve such live updating problems directly. One option...
Read more >Bluebird.js
Bluebird is a fully featured JavaScript promises library with unmatched performance.
Read more >.error | bluebird
Bluebird is a fully featured JavaScript promises library with unmatched performance.
Read more >.done | bluebird
Bluebird is a fully featured JavaScript promises library with unmatched performance.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Awesome. I’ll publish a new version with the fix when I get a chance today.
It’s fixed 👍 😄
Thank you so much @awlayton.