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

Download image throw prompt window, if window_.webContents does not e… #103

Closed
wants to merge 7 commits into from

Conversation

AleshaOleg
Copy link

…xist

@AleshaOleg
Copy link
Author

#81

@sindresorhus
Copy link
Owner

This is unlikely to get merged as-is. I don't think this is the best way to solve the problem. Try to find a solution that doesn't involve adding request and downloads-folder as dependencies.

@AleshaOleg
Copy link
Author

@sindresorhus updated

@sindresorhus
Copy link
Owner

sindresorhus commented Feb 5, 2020

By my previous comment, I meant, try to find a way without having to manually download the image. The Node.js request API is missing a lot of things that you get in Chrome for free, like proxy support and retrying.

I think #104 would be a better solution.

@AleshaOleg
Copy link
Author

Updated solution with ses.downloadURL, but now both buttons "Save Image" and "Save Image to..." behaves in the same way. After clicking on them, the download window appears.

My proposal now to make "Save Image" in https://github.com/sindresorhus/electron-context-menu configurable. What do you think @sindresorhus? I mean, if a developer knows that he is using webview, he might want to hide "Save Image" and leave only "Save Image To...", because ses.downloadURL triggers window from a screenshot below anyway.

Screenshot 2020-03-05 at 16 11 51

I know that this is wrong place to discuss this, but probably some other libraries using electron-d or will use in future with webview and for them that might be kind of unexpected.

Also, one more restriction, that I'm reading session from persist:webview, because the session is not available in webview without defining partition param for it. Here is more info. We might need to add more default names for that param which we will try to read or pass session name as param.

The last build is timed out, can you please re-run it?

Thanks!

@sindresorhus
Copy link
Owner

Download image throw prompt window, if window_.webContents does not exist

Why does webContents not exist?

@sindresorhus
Copy link
Owner

I feel like you're trying to solve a problem we don't fully understand, that could maybe even be an Electron bug.

@sindresorhus
Copy link
Owner

Updated solution with ses.downloadURL, but now both buttons "Save Image" and "Save Image to..." behaves in the same way. After clicking on them, the download window appears.

You receive the DownloadItem. Can you not set .setSavePath() on it to prevent the save dialog?

https://github.com/electron/electron/blob/eb6660f5341d6d7e2143be31eefec558fd866c84/docs/api/download-item.md#downloaditemsetsavepathpath

@AleshaOleg
Copy link
Author

Download image throw prompt window, if window_.webContents does not exist

Why does webContents not exist?

most likely because I'm using webview to display page

@AleshaOleg
Copy link
Author

I feel like you're trying to solve a problem we don't fully understand, that could maybe even be an Electron bug.

that might be, yeah. But I don't know where to dig

@AleshaOleg
Copy link
Author

AleshaOleg commented Mar 9, 2020

Updated solution with ses.downloadURL, but now both buttons "Save Image" and "Save Image to..." behaves in the same way. After clicking on them, the download window appears.

You receive the DownloadItem. Can you not set .setSavePath() on it to prevent the save dialog?

https://github.com/electron/electron/blob/eb6660f5341d6d7e2143be31eefec558fd866c84/docs/api/download-item.md#downloaditemsetsavepathpath

ses.downloadURL() doesn't return anything. It just generates new DownloadItem which should be accessible via will-download, but it's not, unfortunately.

just tried that solution, still can see save dialog. Here is a code which I tried:

const ses = remote.session.fromPartition('persist:webview');

if (ses) {
	ses.on('will-download', (event, item, webContents) => {
		event.preventDefault()
		require('request')(item.getURL(), (data) => {
			item.setSavePath(os.homedir() + '/Downloads/image.jpeg')
		});
	});

	ses.downloadURL(url);
}
  1. event.preventDefault() should prevent to show save dialog.
  2. item.setSavePath(os.homedir() + '/Downloads/image.jpeg') not actually working at all, and even after using event.preventDefault() and item.setSavePath() I can see save dialog.
  3. Result for console.log(event, item, webContents) is {}, {}, null
  4. item.getURL() works perfectly and returns URL.

How you think should it work for webview or this is Electron bug, and I should create an issue there?

Thanks!

@sindresorhus
Copy link
Owner

This sounds like an Electron bug. I would encourage you to open an issue over there.

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

Successfully merging this pull request may close these issues.

2 participants