add features for asynchronous downloads #1373
Conversation
.. note:: | ||
|
||
since phantom 2.0.0 synchronous downloads are forbidden : By default async is true / For backward compatibilty async is false with phantom 1.x.x:: | ||
|
||
casper.start('http://www.google.fr/', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would never ever change the API behavior (i.e. default values) depending on the engine in use.
Mark this "obsolete / not recommended" in doc, throw a warning to the output when used and advise to use the newly created "waitForDownload" instead.
Better throw an error if used with an engine that does not support it than silently changing behavior here.
@jefleponot Thanks a lot for this PR 👍 . It seems that you have a regression with form selects in your patch. Some builds fail for receipt of JSON content. Please:
I would never silently change the API behavior due to the engine version in use, though.
I would really like to integrate this PR into 1.1 because it is a major improvement. |
your are totaly right. You would never ever change the API behavior (i.e. default values) depending on the engine in use. The code will now throw an error. I find my regression trouble with meld diff-tools. Thanks for all your brillant analyses. |
8f20934
to
4f406de
Compare
partial PR done. CU next time Thanks in advance Sorry it works now :-) |
Nice! Thanks a lot. Restarted the failing job (known intermittent popup bug). Will review, ask a second collaborator for opinion and then merge. |
I have done a lot of improvements of CasperJS for my web service supervision job, that I newer commit. if you are interested in lots of PR, it will valid them. |
@jefleponot Sounds good. Maybe it would be best to create separate feature branches to help make the different change-sets small. Any improvement is welcome. Especially those that help to close the numerous open issues. Thanks for your support. |
|
||
Saves a remote resource onto the filesystem. You can optionally set the HTTP method using the ``method`` argument, and pass request arguments through the ``data`` object (see `base64encode()`_):: | ||
|
||
.. note:: | ||
|
||
since phantom 2.0.0 synchronous downloads are forbidden : By default async is true / For backward compatibilty async is false with phantom 1.x.x:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PhantomJS instead please :)
@jefleponot great contribution ! some comments to address then. But I'm 👍 to merge this feature :) |
@mickaelandrieu thanks for quick review. :) Maybe let's discuss the question:
vs.
approach with @n1k0, @hexid, and @paazmaya... EDIT (see also discussion at #1342) |
5097b9c
to
74b91a0
Compare
Another issue for you @istr : casperJS has never used "window.callPhantom" method before this PR. "window.callPhantom" is similar to the "window.postMessage" function : postMessage(data, targetDomain) So it could be great to use the same object attributes The special propertys of a message event are: data The first argument of postMessage origin The source domain source The reference to sending window if it is possible to respond by calling event.source.postMessage chrome extensions has yet normalize communications with the "message passing" : In the modules/casper.js file a senMessage method could be add like the chrome.tabs.sendMessage : sendMessage(integer tabId, any message, object options, function responseCallback) Thanks for yours advices |
74b91a0
to
ed61db6
Compare
@istr sounds OK to me 👍 |
@jefleponot I tried patching this change into the source code myself and notice that it still produce zero byte files. So I am wondering if the way the script is written need to be changed as well in order for the bug to be fixed. |
Hi @eloitay Or you can do a PR with an example. |
@@ -410,7 +437,7 @@ Also have a look at `forward()`_. | |||
``base64encode()`` | |||
------------------------------------------------------------------------------- | |||
|
|||
**Signature:** ``base64encode(String url [, String method, Object data])`` | |||
**Signature:** ``base64encode(String url [, String method, Object data, Boolean async])`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would give the impression that the third parameter is required when the second is given.
Perhaps (String url [, String method [, Object data, Boolean async ] ] )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
ed61db6
to
c068b13
Compare
Do we want to keep this issue in the 1.1 release @istr @mickaelandrieu? I vote to move to a new milestone 1.2. I feel like this would be good for a 1.2 considering our focus on squashing bugs for 1.1. This is something I'd be happy to pick up in the future. Feel free to assign to me. |
Humm ok for 1.2, how many issues are blocking the release of 1.1 according to the actual milestone? |
test ok - PhantomJS 1.9.7 -> 2.1.1 code : var casper = require("casper").create();
casper.start("http://www.google.fr/", function() {
this.download("http://www.google.fr/images/srpr/logo3w.png", "logo.png",'GET',{},true);
});
casper.then(function(){
this.waitForDownload("http://www.google.fr/images/srpr/logo3w.png",function(){
console.log('download sucess');
}, function(){
console.log('download failed');
});
});
casper.run(); It is fully functional , works in production since January 2016 with phantomJS 2.1.1 because old download method can't be used |
013a1ab
to
7a324e8
Compare
@mickaelandrieu : update done |
@jefleponot sadly, your last merged pull request have been merged and so on you need to rebase this one 💃 @casperjs/contributors so, are we agree to merge this one? my vote is 👍 |
I would prefer not to break the API in this way:
See https://github.com/casperjs/casperjs/issues/1342#issuecomment-207848750 what I would like to see in this PR instead:
|
Thanks for your explanation. you are right, this PR don't suit for many reasons.
With PhantomJS and SlimerJS, on the opposite, methods are mixed synchronous or asynchronous :
If you look for an equivalent approach like chrome.tabs, every methods are fully asynchronous :
CasperJS has same trouble as PhantomJS and SlimerJS : mix synchronous and asynchronous fct. download() - synchronous The use of Synchronous mode, although it eases writing limits treatments. @istr, could we propose a new set of asynchronous functions what could lead CasperJS to good javascript practices ? |
@jefleponot @istr I agree with Jef, and we need to keep the old api. Could be better for now to create new functions instead of improve the existing one (and this may be a good start for 2.0 api :) ) |
Someone what happened with this request? |
Archiving PR using ARCHIVE label as CasperJS, like PhantomJS, is not actively maintained for now. These PRs are from 1-5 years ago but there just hasn't been maintainers to continue the work. |
To solve asynschronous downloads that does work with phantomjs v2 (issue : Synchronous XHR causing zero byte file downloads #1342 ), there is a proposal PR
for @langholz and @istr , thanks to your specifications.
PS : operation synchronously javascript is simply an absurdity because it inhibits the language spirit.
PS : PS : Could it be possible that a great tools as CasperJS be written to use asynchronous methods
(http://phantomjs.org/api/webpage/method/evaluate-async.html)
We could use it in more domains like "chrome extension tabs" : https://developer.chrome.com/extensions/tabs#method-executeScript
Best Regards
jef