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

onLoadFinished not triggered #10265

Closed
gregwebs opened this issue Oct 18, 2011 · 30 comments
Closed

onLoadFinished not triggered #10265

gregwebs opened this issue Oct 18, 2011 · 30 comments

Comments

@gregwebs
Copy link

g...@gregweber.info commented:

version: 1.3.0

Note, I am using the ghostbusters library to use phantom.js, but I don't think that should effect anything.

reproduce:

  1. Hook up to the callbacks

    @page.onLoadStarted = () -> console.log "LOAD STARTED"
    @page.onLoadFinished = (status) -> console.log("LOAD FINISHED: status " + status)

  2. Observe that only LOAD STARTED is seen.

expected:

LOAD FINISHED should have also been seen.

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

@ariya
Copy link
Owner

ariya commented Oct 18, 2011

ariya.hi...@gmail.com commented:

Which URL shows this problem?

@gregwebs
Copy link
Author

g...@gregweber.info commented:

I don't ever see that the load is finished. I am running a test that opens a page, fills out a form and clicks a submit. that submit opens a new page. I see 2 starts in the console but no finishes.

@ariya
Copy link
Owner

ariya commented Oct 19, 2011

ariya.hi...@gmail.com commented:

It would be hard to believe that onLoadFinished is not triggered, a lot of examples rely on this behavior.

If there is a new page opened, then it may be that finish callback needs to be implemented for the page.

@ariya
Copy link
Owner

ariya commented Nov 28, 2011

sylvinus@gmail.com commented:

I'm also not seeing any onLoadFinished() callbacks firing, even on very simple hello world pages. (mac os x 10.6)

@ariya
Copy link
Owner

ariya commented Nov 28, 2011

ariya.hi...@gmail.com commented:

Here's a super simple script to try. If running PhantomJS with this script does not give the finish message, something is seriously wrong. Otherwise, please post the test case which demonstrates "onLoadFinished not firing" situation.

var page = new WebPage();

page.onLoadStarted = function () {
console.log('Start loading...');
};

page.onLoadFinished = function (status) {
console.log('Loading finished.');
phantom.exit();
};

page.open('http://example.com');

@ariya
Copy link
Owner

ariya commented Dec 20, 2011

ariya.hi...@gmail.com commented:

Ping.

@scophotog
Copy link

scott....@gmail.com commented:

Not sure if this is related. It seems onLoadFinished doesn't actually wait for the page to completely finish loading. I have a script which loads multiple pages and then runs a check on each. It loads the URLs from a JSON file:

var objs = JSON.parse(data)

for (i = 0; i < objs.length; i++) {
(function(obj) {
var page = new WebPage();
page.open(obj.url);
page.onLoadFinished = function() {
var c = page.evaluate(function() {
//return something
});
console.log('Output ' + c);
}(objs[i]);
}

With 1 record, it loads and works. With 3 records, I can see it trying to output to the console but the page isn't completely loaded, then when the pages finally load I'll get the output from within onLoadFinished. To see the effect use sites that are fairly content heavy.

@ariya
Copy link
Owner

ariya commented Mar 14, 2012

ariya.hi...@gmail.com commented:

I'm not sure I understand the 3 records problem. Do you see 3 'Output...' at once? Are they all wrong?

Another thing to try is to insert another console.log before calling page.evaluate, just to show the loading status.

@magopian
Copy link

mathieu....@gmail.com commented:

Running the "simple" script above did indeed give me a "loading finished". However this very small variation didn't:

var page = new WebPage();

page.onLoadStarted = function () {
console.log('Start loading...');
};

page.onLoadFinished = function (status) {
console.log('Loading finished.');
phantom.exit();
};

page.open('http://example.com', function(status) {
console.log('loading');
});

@ariya
Copy link
Owner

ariya commented Jun 22, 2012

t...@arachnys.com commented:

WebPage#open replaces page.onLoadFinished with the callback you pass it - it's totally non-obvious, and I only realised this by looking at the Casper.js source, and then the phantom source.

See https://github.com/ariya/phantomjs/blob/master/src/modules/webpage.js#L141 . I imagine you could verify if with

page.onLoadFinished = function (status) {
console.log('Loading finished.');
phantom.exit();
};

var handler;
page.open('http://example.com', handler = function(status) {
console.log('loading');
});
console.log("onLoadFinished stomped:",handler === page.onLoadFinished);

@ariya
Copy link
Owner

ariya commented Sep 4, 2012

ariya.hi...@gmail.com commented:

Second ping.

@detro
Copy link
Collaborator

detro commented Sep 26, 2012

detroniz...@gmail.com commented:

I can confirm this issue is real.

Comment #10 explains the issue well.

I'm working on a fix of this.

 
Metadata Updates

  • Label(s) added:
    • webdriver
  • Milestone updated: FutureRelease (was: ---)
  • Owner updated: detroniz...@gmail.com

@detro
Copy link
Collaborator

detro commented Sep 26, 2012

detroniz...@gmail.com commented:

Issue 504 has been merged into this issue.

@detro
Copy link
Collaborator

detro commented Sep 26, 2012

detroniz...@gmail.com commented:

Issue 376 has been merged into this issue.

@ariya
Copy link
Owner

ariya commented Sep 26, 2012

ariya.hi...@gmail.com commented:

Comment #10 described the documented behavior. I'm not sure it explains the issue.

Here is a test script:

var page = require('webpage').create();

page.onLoadStarted = function (status) {
  console.log('Start');
};

page.onLoadFinished = function (status) {
  console.log('Finish 1');
  phantom.exit();
};

page.open('http://example.com', function() {
  console.log('Finish 2');
  phantom.exit();
});

The output is:

Start
Finish 2

which is pretty much as expected.

I wonder which situation/URL will never give onLoadFinished at all.

@detro
Copy link
Collaborator

detro commented Sep 26, 2012

detroniz...@gmail.com commented:

The behaviour should be a double trigger: 1 for the callback registered for "onLoadFinished" - the other for the page.open callback provided.

The code above shows that a callback set with "page.open" override the onLoadFinished previously set.

While the reason is obvious (we use that signal to trigger the open callback), the behaviour that I would expect (and I think others expect too) is that we fire both: the registered handler AND the callback provided by open.

I have a solution to this btw.
Just need some time to polish stuff and catch some sleep.

@JamesMGreene
Copy link
Collaborator

james.m....@gmail.com commented:

I also have a solution to this, though mine is more of a complete paradigm shift (I redesigned the event API). Will try to commit my ideas soon to share, maybe tonight even.
~~James

@ariya
Copy link
Owner

ariya commented Sep 26, 2012

ariya.hi...@gmail.com commented:

If we want to change the behavior, better discuss it in the mailing-list and open a new issue.

Reading through the origina post of this bug, it has nothing to do with override of onLoadFinished.

@detro
Copy link
Collaborator

detro commented Sep 26, 2012

detroniz...@gmail.com commented:

@ariya: to me sounds like this story is ALL about onLoadFinished being overridden.
Infact, Greg above said:

"LOAD FINISHED should have also been seen."

I understand that maybe what you are saying is that "the expectations were wrong - that's not the behaviour", but I actually think it's an "expectable" behaviour that we silently override.

Will open a new issue and spin up a mailing list discussion.
This story, in the mean time, I'll mark as "WontFix".

 
Metadata Updates

  • Status updated: WontFix

@detro detro closed this as completed Sep 26, 2012
@ariya
Copy link
Owner

ariya commented Sep 26, 2012

ariya.hi...@gmail.com commented:

"LOAD FINISHED should have also been seen."

I would have agreed to that if there was ever a confirmation that page.open is being called with an extra handler, unlike my example in comment #5.

Newly spawn issue is issue 801: onLoadFinished should trigger even if a callback is provided for "page.open()".

@detro
Copy link
Collaborator

detro commented Sep 26, 2012

detroniz...@gmail.com commented:

Sorry. Can you rephrase? I'm not sure I understand what you mean here.

@ariya
Copy link
Owner

ariya commented Sep 26, 2012

ariya.hi...@gmail.com commented:

The OP needs to post the entire script so that we can confirm whether it is (1) onLoadFinished + open(url, handler) or just (2) onLoadFinished + open(url).

@detro
Copy link
Collaborator

detro commented Sep 26, 2012

detroniz...@gmail.com commented:

From comment #2 I understand that he operates on the page after has loaded.
He doesn't know (and that's my point about confusing API behaviour) that the very handler he uses to operate on the page, has disabled his "onLoadFinished".

Another example of this is at the Issue #801 that I opened.

@alonmove
Copy link

happens to me as well. onLoadFinished callback not fired.

@thomasmodeneis
Copy link

what was the resolution for this ???

@anusha121212
Copy link

Hi am trying to call ajax request using Phantom js and selenium java bindings. Please find the requirement and issue am facing below:
Requirement:
Need to drag and drop widget
while drag and dropping ajax call is made-----here page keeps on loading it doesn't stop. please help me to solve dis. on this particular scenario all test cases are based.

@BES1st
Copy link

BES1st commented Sep 12, 2016

Hello @ariya ,

Can you try the code with this url: http://vilagutazo.blog.hu ?
Lot of Finish1 and lot of Finish 2 in the console log.
Million thanks!

Gabor

@BES1st
Copy link

BES1st commented Sep 13, 2016

and I have an little problem:
Crash Annotation GraphicsCriticalError: |[0][GFX1-]: Too many dropped/corrupted frames, disabling DXVA (t=14931.3)[GFX1-]: Too many dropped/corrupted frames, disabling DXVA
What's this? Can you help me?

Thanks!

Gabor

@iyyappan13391
Copy link

Some guys made duplicate and closed and merge..etc,What is the solution for this???

@phantom developer's what doing???

page.onLoadFinished = function (status) {
console.log('Loading finished.');
phantom.exit();
};

@drcrack
Copy link

drcrack commented Nov 24, 2017

still not working

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