Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting stuck on 'Failed to load Url error' when using co.js #308

Open
ahmedrad opened this issue Aug 27, 2017 · 0 comments
Open

Getting stuck on 'Failed to load Url error' when using co.js #308

ahmedrad opened this issue Aug 27, 2017 · 0 comments

Comments

@ahmedrad
Copy link

ahmedrad commented Aug 27, 2017

I'm writing a simple script to open multiple webpages in multiple tabs. I'm running into a problem where if one of the pages doesn't load successfully with error 'Failed to load url' every promise after that rejects with 'Failed to load url'. I'm wondering why it's not just getting over the fact that one tab opening failed and refuse to run anymore unrelated operations!

script:

var Horseman = require('node-horseman');
var co = require('co');
var horseman = new Horseman();

var links = ['https://www.hotjar.com/blog','https://insights.hotjar.com/register','https://www.hotjar.com'];

co(function *(){
  for (var link of links) {
    try {
      yield horseman.openTab(link);
    }
    catch(err) {
      console.log(`error opening a tab: ${link} ${err}`);
    }
  }
  try {
    var tabCount = yield horseman.tabCount();
    console.log(tabCount);
  }
  catch(err) {
    console.log("can't get tab count: " + err);
  }
  try {
    var url = yield horseman.switchToTab(0).url();
    console.log(url);
  }
  catch(err) {
    console.log("can't get first tab's url: " + err);
  }
  return url;
}).then(function(r){
  console.log('result:');
  console.log(r);
})
.catch(function(e){
  console.log("final error handler: " + e);
});

Output of: DEBUG=horseman BLUEBIRD_DEBUG=1 node co.js

horseman using PhantomJS from phantomjs-prebuilt module +0ms
  horseman .setup() creating phantom instance 1 +113ms
  horseman phantom created +982ms
  horseman phantom version 2.1.1 +21ms
  horseman page created +14ms

  horseman phantomjs onLoadFinished triggered success NaN +18ms
  horseman injected jQuery +35ms
  horseman page created +21ms
  horseman phantomjs onLoadFinished triggered success 1 +7s
  horseman jQuery not injected - already exists on page +5ms
  horseman page created +17ms
  horseman phantomjs onLoadFinished triggered fail 2 +2s
error opening a tab: https://insights.hotjar.com/register Error: Failed to load url
error opening a tab: https://www.hotjar.com Error: Failed to load url
can't get tab count: Error: Failed to load url
can't get first tab's url: Error: Failed to load url
result:
undefined
  horseman phantomjs onLoadFinished triggered success 3 +1s
  horseman injected jQuery +16ms

using node/6.10.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant