NagyI
NagyI

Reputation: 5997

Catch file download events in Electron app

I'm writing a wrapper desktop application around a webpage using Electron. I'm using a <webview> control to display the page. Noticed that if i click on a link which result in a file download in a normal browser (the HTTP response has Content-Disposition header) does nothing in Electron, which is fine by me since i like to control what happens to downloaded files. The app will run in a restricted environment.

Can't seem to figure out how can i catch the download event. There is the did-get-response-details event which gets fired when i click on the link, but i can't access any response data (at least the headers), nor it states that Electron will not handle this link so i can do whatever i want to do with it on my own, like fetching it with the node.js API.

Upvotes: 3

Views: 2543

Answers (1)

NagyI
NagyI

Reputation: 5997

Response headers are available in the mentioned event as soon as this patch gets merged: https://github.com/atom/electron/pull/1604 After that downloads can be caught by checking for the Content-Disposition header.

Upvotes: 1

Related Questions