Downloading Silently by Chrome Extension - javascript

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.

Related

Is it possible to programmatically cancel/stop a started download from JavaScript?

Our application implements a custom download manager.
So actually this means that when a user starts a download of a resource he/she has the opportunity to cancel it through a UI button from the app, which actually sends some event to the server to cancel the downloading (the connection is disconnected and etc).
But since recently Chrome added auto-resume of failed downloads, so the same request is resumed to be downloaded again from the Chrome Download Manager, it's because Chrome cannot distinguish that the user/server intentionally canceled the HTTP connection so it revokes it again.
Currently, we download resources using IFrame, but once the download is started by the browser changing the IFrame's src attribute is not relevant anymore. I've tried to use <a href='...' download> but the issue is the same.
Maybe there's some API at least for Chrome? (There's actually such for Chrome extensions but this is not the case)
You cannot control the downloads that are managed by the download manager, of the browser.
If you want to control the download then you need to fetch the file JavaScript by e.g. utilizing the Streams API.
After you downloaded the Data you can pass that file to the download manager of the browser.
Each of those tasks can be solved in different ways.
Could you do something like add a unique key to the URL for each download request? When the user cancels the download, you invalidate the key so that the URL cannot be used again to download that resource - and in the process prevents Chrome from being able to resume the download.

Does chrome extension api support downloads directly from browsing cache?

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.

Initiate download without iframe

I'm looking to initiate a download in a webpage using either JavaScript or PHP. All of the examples I've seen use an iframe to load the source of the file. Unfortunately this method doesn't seem to work with all smartphone browsers, specifically my Samsung Galaxy S3. It seems to be a known issue with some of Android's stock browsers.
I cannot use a link because the download must happen auto-magically, and using document.ready or window.load to initiate a window.location call is not acceptable because even though the download initiates it stops all the JS functionality on the current page. I have some JavaScript that must run after the download has initiated.
Basically the flow is:
Show JavaScript progress bar to simulate download progress
Initiate download in background
Once progress bar finishes -> jquery.show new content on page (installation instructions)
Can't seem to find a cross-browser solution that will let me get through all 3 steps above.

Precache file with Javascript in the browser?

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.

How can I add a URL to the download manager in a Chrome Extension?

I've been working on an extension that checks for certain URLs in page content and lets the user put a button to automatically put these into the download manager. I've gotten everything I need, but how do I actually tell Chrome to put the URL into the download queue?
You can't, its not supported yet. There are no extensions for Chrome download manager.

Categories