I have a URL which onclick it downloads a file. Some of these files are quite big and it takes some time for the browser to receive it. This can be frustrating for the user, especially for the inexperienced ones, who don't realize that the file is about to be downloaded.
I tried to add the tag "download" in the element but it doesn't work for my Chrome, Firefox version. As an alternative I added:
target = "_blank"
Which opens a new blank page and once the download starts it closes it. But this solution is not very elegant.
Is there a way to track when the browser will receive the file? So I am able to show an indicator?
Related
I need my extension to bulk download assess in a web page.
I set saveAs:false for chrome.downloads.download so that I do not get saveAs dialog. But when download starts, download bar at the bottom of the browser gets opened and all list of downloads puts into it. This clutters the download bar and Chrome interface.
Is it possible to prevent download bar from opening and not put the downloads that are started by an extension?
It's possible to hide the download bar (called shelf in Chrome UI lingo) completely, but not filter out specific downloads.
chrome.downloads.setShelfEnabled(false); // requires "downloads.shelf" permission
You can clear out your downloads from the download list with chrome.downloads.erase method.
Consider an alternative (if more technically challenging) approach of "downloading" through XHR to a temporary HTML5 FileSystem, forming an archive file, and then calling chrome.downloads on that. May not work if you need all the files immediately unpacked.
I'm implementing a simple web picture grabber, using chrome.downloads api.
I grab the image urls in content script, and then call chrome.downloads.download to download them in the background script. It works well, but I want it faster.
I find that if users click "save image as" in the context menu of <img> object, the downloading speed is very fast and almost seamless. I think it downloads directly from cache.
However, using chrome.downloads seems independent of the loading of <img> objects; even though pictures are already loaded on the webpage, chrome.downloads.download takes some time to download each image, not so fast as "save image as". So I think it download from the url, regardless of cache.
In fact, doing so has each picture downloaded twice: one to cache to browser display, the other to download folder. It's clearly a waste of time and net resource.
So... back to the topic: is there any api supporting downloading directly from the chrome's browsing page? Just like "save image as".
I have asked the same question before. Chrome APIs for the public is really backward. They don't really have most features the browser offers.
In short, no, you cannot. "Save image as" is the only way you can access the cache and save them to another location on your disk.
I am automating a website with WebDriver but my file download needs are a little different from those I have found when googling.
I have a website which creates orders. When I click the 'place order' button, it redirects me to the Print Order page. As a "convenience" for me, this page automatically launches the download operation in its body onload, meaning that when I click the 'place order' button, I go to a new page and then a file download dialog immediately appears to let me download the generated pdf, thus blocking the browser.
Here are the solutions I found/thought of, and why I couldn't use them:
Configure Firefox/Chrome profiles to silently download files. Can't use this because I have the requirement of timing how long the download takes.
Override window.open with a function that prevents the download, and allows me to grab the URL and download it with wget. Can't use this because the file download is started from the onload function of the next page, so any javascript I run on this page will be lost.
Cancel the onload function or try to execute code before the onload function. Can't find a way to do this in webdriver.
Download the print page with wget, modify the html to change the onload handler, and inject the modified html back into selenium. Can't find a way to replace an entire page, including <head> and <body> tag and URL.
Unfortunately I can't change the source code of this website because I am in QA and I don't have that sort of leverage with development. Does anyone have any ideas for a way to download this file in an automatic manner that can be timed?
Thanks.
Seems to me you have 2 options.
Use an AUTOIT script to download the file once you receive the popup, this tests the functionality of the page opening and the download.
Download the file just using http get. This misses out testing that the page loads but will still check that the file exists.
The other tests you mention above seem to be too complicated.
How can I do this:
the page loads
javascript loads a remote PDF file into local memory
the user clicks a button/link
the system launches the PDF reader or starts a download dialog with the PDF file already in memory
In other words, it's a regular file download in the browser EXCEPT that the file has already been loading in the background in order to speed up its receipt when/if the user decides to download the file.
You would have to encode the file (perhaps via a servlet), then you could get it through an XHR, and write it into a data uri, which you could then attach to a button or link.
This technique would probably only work on small files and very recent browsers.
StackOverflow won't let me post an example link as a link, so to test the concept, you'll have to copy the following line into an html file and see if you can load the link:
pdf link
This worked perfectly in Chrome when I tested it just now, and worked partially in Firefox. It didn't work at all in my version of IE.
Another potential solution is to make absolutely sure that the pdf is being cached, and then try to load it in a hidden iframe. Whether this works or not will depend on how the user has their browser set up.
You should consider not doing it at all, given the difficulties.
We have a file handling ASP.Net web control used in intranet web applications, that currently uses ActiveX to handle file check-outs, and check-ins. Works fine, in IE&Win.
But now we are trying to get rid of ActiveX & IE only behavior...
If a file is checked out, it is copied to file share, with access right limited to the checking-out user.
Using a hidden iframe, and setting the src of the iframe to something like "file:////file_share/dictionary/users_stuff/someDoc.doc", an open/download dialog is shown, so the user can open and edit the shared file in Word, Excel, etc directly from the file share.
Works fine for file types browsers can't handle themselves.
But for file types like txt, images, html the browser simply loads the file to the iframe, or opens the file, if the user is given a link. And the user can't edit the file without manually launching the appropriate application and copying the url. Showing the users a "Copy this url to your preferred application, and try to edit it" would not be really user friendly...
My question is: is it possible to get the browser (without ActiveX, IE...) to pass the link to the OS, or show a "What do you want to do with this file" dialog of some sort?
If not, what and how could be achieved?
The closest I could come up with is this thread:
https://stackoverflow.com/a/1394725/1195927
#Red says no (and the original poster agrees) BUT #Daan seems to have a solution.
I have not tested, so YMMV.
If a javascript/html solution is not found, I may have an ugly hack for you . . .
See my post here: Launching a Downloadable Link