node-phantom-simple icon indicating copy to clipboard operation
node-phantom-simple copied to clipboard

onLoadFinished arguments wrong with SlimerJS

Open awlayton opened this issue 8 years ago • 12 comments

SlimerJS passes 3 arguments to the onLoadFinished callback, while PhantomJS only passes 1.

If one registers an onLoadFinished callback taking 1 argument and is using SlimerJS, the callback will be called with an array of the 3 arguments as the first argument.

I believe the problem stems from this section. It appears this issue will happen whenever the callback has one argument but is called with multiple arguments.

This is related to johntitus/node-horseman#180

awlayton avatar May 11 '16 19:05 awlayton

Suggestions? No idea why that magic with wrap/unwrap arrays was done, looks suspicious. It existed in v1.0 and we did not changed anything there. I have no principal objection to bump version to 3.0 and remove all legacy mess.

@baudehlo may be you remember something about that code :) ?

puzrin avatar May 12 '16 14:05 puzrin

My suggestion would be to always use .apply rather than .call, like you said. I also think it looks like it is doing something weird...

awlayton avatar May 12 '16 14:05 awlayton

I have no recollection of anything - sorry - I haven't worked on this code in years.

On Thu, May 12, 2016 at 10:43 AM, Alex Layton [email protected] wrote:

My suggestion would be to always use .apply rather than .call, like you said. I also think it looks like it is doing something weird...

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/baudehlo/node-phantom-simple/issues/133#issuecomment-218779300

baudehlo avatar May 12 '16 15:05 baudehlo

@awlayton could you do a PR with test?

puzrin avatar May 12 '16 15:05 puzrin

I am working on a paper right now. I might be able to get to it this weekend, maybe.

awlayton avatar May 12 '16 21:05 awlayton

I tried to make a test, but now I can't get the bug to happen @puzrin. What SlimerJS were you using @winghouchan?

awlayton avatar May 13 '16 20:05 awlayton

I'm using SlimerJS 0.10.0 @awlayton.

winghouchan avatar May 14 '16 12:05 winghouchan

I have a feeling that the problem caused by using .call rather than .apply in this situation is a lot more expansive. This is coming from a case I just witnessed with a callback on the consoleMessage event. When running the callback in PhantomJS, 3 arguments are expected:

const webPage = require('webpage');
const page = webPage.create();

page.onConsoleMessage = (msg, lineNum, sourceId) => {
  console.log(`CONSOLE: ${msg} (from line #${lineNum} in ${sourceId})`);
};

However a consoleMessage callback in SlimerJS gets passed the first argument with an array of elements corresponding to each expected argument.

Perhaps more investigation is required to see how far this issue expands exactly.

winghouchan avatar May 15 '16 22:05 winghouchan

Yes the problem potentially affects all callbacks @winghouchan. Perhaps you have more time to make a test and fix for this issue?

awlayton avatar May 16 '16 16:05 awlayton

I'm certainly open to putting a PR together for this. However my time is also limited so it won't be something I'm prioritising right now.

winghouchan avatar May 17 '16 20:05 winghouchan

After last surprise with banned slimerjs downloads on travis, i decided to spend some resources to significantly improve things. And we transparently migrated our testing lib to electron :) . https://github.com/nodeca/navit (now in dev branch). My impression is that Electron is much more stable and predicatable. Slower than phantom, but faster than slimer.

puzrin avatar Jun 16 '16 15:06 puzrin

Can we except a merge ?

y0hnn avatar Jun 28 '17 13:06 y0hnn