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

Projects
None yet
2 participants
@trop
Copy link
Contributor

commented Jan 31, 2019

Backport of #16612

See that PR for details.

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

fix: Use async save dialog for anchor download attribute
On macOS, the synchronous save dialog does not work properly and breaks
in weird ways when the dialog is expanded/collapsed (see #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 as a code owner Jan 31, 2019

@trop trop bot added 5-0-x backport labels Jan 31, 2019

@zcbenz

zcbenz approved these changes Jan 31, 2019

@zcbenz zcbenz merged commit 4d7ddcd into electron:5-0-x Jan 31, 2019

19 of 22 checks passed

appveyor: win-ia32-testing-pr AppVeyor build failed
Details
ci/circleci: mas-testing-tests Your tests failed on CircleCI
Details
ci/circleci: osx-testing-tests Your tests failed on CircleCI
Details
Absolute Zero
Artifact Comparison No Changes
Details
Semantic Pull Request ready to be squashed
Details
WIP Ready for review
Details
appveyor: win-x64-testing-pr AppVeyor build succeeded
Details
ci/circleci: linux-arm-debug Your tests passed on CircleCI!
Details
ci/circleci: linux-arm-testing Your tests passed on CircleCI!
Details
ci/circleci: linux-arm64-debug Your tests passed on CircleCI!
Details
ci/circleci: linux-arm64-testing Your tests passed on CircleCI!
Details
ci/circleci: linux-checkout Your tests passed on CircleCI!
Details
ci/circleci: linux-ia32-debug Your tests passed on CircleCI!
Details
ci/circleci: linux-ia32-testing Your tests passed on CircleCI!
Details
ci/circleci: linux-ia32-testing-tests Your tests passed on CircleCI!
Details
ci/circleci: linux-x64-debug Your tests passed on CircleCI!
Details
ci/circleci: linux-x64-testing Your tests passed on CircleCI!
Details
ci/circleci: linux-x64-testing-tests Your tests passed on CircleCI!
Details
ci/circleci: mas-testing Your tests passed on CircleCI!
Details
ci/circleci: osx-testing Your tests passed on CircleCI!
Details
release-notes Release notes found
@release-clerk

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.