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

fix: Use async save dialog for anchor download attribute (backport: 5-0-x) #16640

Conversation

trop[bot]
Copy link
Contributor

@trop trop bot commented Jan 31, 2019

Backport of #16612

See that PR for details.

Notes: Fix broken save dialog on macOS for <a> downloads

On macOS, the synchronous save dialog does not work properly and breaks
in weird ways when the dialog is expanded/collapsed (see electron#14606). This
works around the problem for the dialog shown for `<a download=...>` by
switching to the asynchronous API.

To test this:

main.js:
```
const { app, BrowserWindow, session } = require('electron')
const path = require('path')

function createWindow() {
  win = new BrowserWindow({
    width: 600,
    height: 600,
    webPreferences: {
      nodeIntegration: false,
    },
  })

  session.defaultSession.on('will-download', (event, item) => {
    // Test with and without this commented out.
    //item.setSavePath(path.join(app.getPath('desktop'), 'test-download.txt'))
  })

  win.loadURL(`file://${__dirname}/test.html`)
}

app.on('ready', createWindow)
```

test.html:
```
<html>
<head>
  <meta http-equiv="Content-Security-Policy" content="default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline'; img-src 'self' data:">
</head>
<body>
<a href="data:application/xml;charset=utf-8,foo" download="download.txt">Save</a>
</body>
```
@trop trop bot requested a review from a team January 31, 2019 02:07
@trop trop bot added 5-0-x backport This is a backport PR labels Jan 31, 2019
@zcbenz zcbenz merged commit 4d7ddcd into electron:5-0-x Jan 31, 2019
@release-clerk
Copy link

release-clerk bot commented Jan 31, 2019

Release Notes Persisted

Fix broken save dialog on macOS for <a> downloads

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5-0-x backport This is a backport PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants