Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

will-download is not emitted when URL is HTML pages #5278

Closed
dennyferra opened this issue Apr 24, 2016 · 2 comments
Closed

will-download is not emitted when URL is HTML pages #5278

dennyferra opened this issue Apr 24, 2016 · 2 comments

Comments

@dennyferra
Copy link

  • Electron version: 0.37.5
  • Operating system: Windows 10

When calling a window's webContents.downloadURL(URL) method if the specified URL returns a 404 the will-download event on webContents.session does not fire and instead a dialog pops up asking the user to save an html file (the contents of the 404 page).

Is this expected behavior and is there any event I can listen to or some other way to get around this? I'd like to handle the error differently if possible.

Thanks

@zcbenz zcbenz added the bug label Apr 26, 2016
@zcbenz
Copy link
Member

zcbenz commented Apr 26, 2016

It seems that the will-download event just doesn't fire when the URL is HTML pages.

@zcbenz zcbenz changed the title Using webContents.downloadURL and URL returns 404 will-download is not emitted when URL is HTML pages Apr 26, 2016
@eternalharvest
Copy link

@zcbenz

I have same issue with electron version 11.1.0.
I want to know how to prevent opening save dialog when the server returns 404 not found.
But I don't know how to check the response status code...

mainWindow.webContents.downloadURL('https://example.com/404.html');
mainWindow.webContents.session.on('will-download', (event, item, webContents) => {
    if (/* check if response status code != 200) */) {
        event.preventDefault();
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants