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

Commits on Jan 31, 2019

  1. 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 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>
    ```
    poiru authored and electron-bot committed Jan 31, 2019
    Copy the full SHA
    e576e87 View commit details
    Browse the repository at this point in the history