Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.

PhantomJS hangs on second load call after first fails #10067

Closed
marcneuwirth opened this issue Mar 25, 2011 · 7 comments
Closed

PhantomJS hangs on second load call after first fails #10067

marcneuwirth opened this issue Mar 25, 2011 · 7 comments

Comments

@marcneuwirth
Copy link

marc.neu...@gmail.com commented:

What steps will reproduce the problem?

  1. Starting with loadspeed.js. Trying to hit a second url with results of success or failure

var address = phantom.args[0];

if (phantom.state.length === 0) {
if (phantom.args.length === 0) {
console.log('Usage: ping.js <some URL> <results URL>');
phantom.exit();
} else {
phantom.state = Date.now().toString();
console.log(new Date());
console.log('Loading ' + address);
phantom.open(address);
}
} else {
if(phantom.state === 'saved'){
phantom.exit();
}
else {
var elapsed = Date.now() - new Date().setTime(phantom.state);
phantom.state = 'saved';
var url = phantom.args[1];
if (phantom.loadStatus === 'success') {
url += '&status=1';
phantom.open(url);
console.log('Page title is ' + document.title);
console.log('Loading time ' + elapsed + ' msec');
} else {
url += '&status=0';
phantom.open(url);
console.log('FAIL to load the address');
}
console.log(url);
}
}

  1. Testing with a url that will fail: phantomjs ping.js http://e.com http://google.com
  2. Execution will hang after phantom.open(url) in the else statement if the first url does not have phantom.loadStatus === 'success'

What is the expected output? What do you see instead?
Expected output:
Fri Mar 25 2011 08:54:31 GMT-0400 (Eastern Daylight Time))
Loading http://e.com
FAIL to load the address
http://google.com&amp;status=0

Actual output:
Fri Mar 25 2011 08:54:31 GMT-0400 (Eastern Daylight Time)
Loading http://e.com
Unsafe JavaScript attempt to access frame with URL http://google.com&amp;status=0 from frame with URL http://e.com/. Domains, protocols and ports must match.

What version of the product are you using? On what operating system?
Windows 1.0.0

Please provide any additional information below.
Surrounding phantom.open(url) with try catch does not help

Disclaimer:
This issue was migrated on 2013-03-15 from the project's former issue tracker on Google Code, Issue #67.
🌟   4 people had starred this issue at the time of migration.

@marcneuwirth
Copy link
Author

marc.neu...@gmail.com commented:

Sorry it should be '?status=', missed that when I ripped out some unnecessary code, although it doesn't solve the problem

@ariya
Copy link
Owner

ariya commented Jun 1, 2011

roejame...@gmail.com commented:

This probably doesn't apply to PhantomJS anymore, seeing as for 1.2 we have completely redone the architecture, and the code no longer looks like that.

You can get the latest code from master in Github. Could check if this issue is fixed for you?

@ariya
Copy link
Owner

ariya commented Jun 1, 2011

klein.stephane@gmail.com commented:

Same problem here with 1.1.0, I'll going to test 1.2.0

@ariya
Copy link
Owner

ariya commented Jun 1, 2011

klein.stephane@gmail.com commented:

phantom.sleep don't work in 1.2.0 version :(

@ariya
Copy link
Owner

ariya commented Jun 1, 2011

roejame...@gmail.com commented:

phantom.sleep was removed from the API in 1.2.0 (see issue 78). In replacement, you can use setTimeout (for asynchronous, also executes code after), or Google for more examples.

http://www.google.com/search?client=ubuntu&channel=fs&q=javascript+blocking+wait&ie=utf-8&oe=utf-8
http://www.google.com/search?client=ubuntu&channel=fs&q=javascript+asynchronous+callback&ie=utf-8&oe=utf-8

@ariya
Copy link
Owner

ariya commented Jun 12, 2011

roejame...@gmail.com commented:

There's an error in the script.

phantom.open() will cause the script to cease operation any further and re-execute itself. So it must be at the end, like here:

    console.log('Loading ' + address);
    phantom.open(address);

@ariya
Copy link
Owner

ariya commented Jun 17, 2011

roejame...@gmail.com commented:

Closing because of the error noted in #6. Create another issue if needed.

 
Metadata Updates

  • Status updated: WontFix

@ariya ariya closed this as completed Jun 17, 2011
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants