Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions draftlogs/5838_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Fix unknown filename when exporting charts using new versions of Safari [[#5609](https://github.com/plotly/plotly.js/pull/5609), [5838](https://github.com/plotly/plotly.js/pull/5838)],
with thanks to @rlreamy for the contribution!
14 changes: 7 additions & 7 deletions src/snapshot/filesaver.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ function fileSaver(url, name, format) {
var blob;
var objectUrl;

// Safari doesn't allow downloading of blob urls
if(Lib.isSafari()) {
var prefix = format === 'svg' ? ',' : ';base64,';
helpers.octetStream(prefix + encodeURIComponent(url));
return resolve(name);
}

// IE 10+ (native saveAs)
if(Lib.isIE()) {
// At this point we are only dealing with a decoded SVG as
Expand All @@ -56,6 +49,13 @@ function fileSaver(url, name, format) {
return resolve(name);
}

// Older versions of Safari did not allow downloading of blob urls
if(Lib.isSafari()) {
var prefix = format === 'svg' ? ',' : ';base64,';
helpers.octetStream(prefix + encodeURIComponent(url));
return resolve(name);
}

reject(new Error('download error'));
});

Expand Down
11 changes: 6 additions & 5 deletions test/jasmine/tests/download_test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var Plotly = require('@lib/index');
var Lib = require('@src/lib');

var helpers = require('@src/snapshot/helpers');
var getImageSize = require('@src/traces/image/helpers').getImageSize;
// var helpers = require('@src/snapshot/helpers');
// var getImageSize = require('@src/traces/image/helpers').getImageSize;

var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
Expand Down Expand Up @@ -137,8 +137,8 @@ describe('Plotly.downloadImage', function() {
})
.then(done, done.fail);
}, LONG_TIMEOUT_INTERVAL);

it('should produce right output in Safari', function(done) {
/*
it('should produce right output in Old Safari', function(done) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to keep these commented-out tests around? Unless you want to try and mock canUseSaveLink===false - which I don't really think is worth it at this point - I'd just delete them.

spyOn(Lib, 'isSafari').and.callFake(function() { return true; });
spyOn(helpers, 'octetStream');

Expand All @@ -157,7 +157,7 @@ describe('Plotly.downloadImage', function() {
.then(done, done.fail);
});

it('should default width & height for downloadImage to match with the live graph', function(done) {
it('should default width & height for downloadImage to match with the live graph on Old Safari', function(done) {
spyOn(Lib, 'isSafari').and.callFake(function() { return true; });
spyOn(helpers, 'octetStream');

Expand All @@ -182,6 +182,7 @@ describe('Plotly.downloadImage', function() {
})
.then(done, done.fail);
});
*/
});

function downloadTest(gd, format) {
Expand Down