javascriptjspdfweb-share

Why do Web Share shared files end up with a random name?


I'm using the navigator.share feature to share a PDF generated with jspdf. So far everything is working fine: the file is generated correctly with all the desired contents and it can be shared/downloaded without any major issue. The problem is that the document's name is being changed to a random name, always in the form of "share"+bunchOfNumbers+".pdf", ignoring the defined name on the File creation.

The only posts I've found regarding this issue are Why web share API converts file name in random? and navigator.share api in android changes the name of the file that the user shares, and also this already closed bug, but none of them got any answer/resolution.

Here is my code to share the file:

if (navigator.canShare && navigator.userAgentData.mobile) {
  var pdf = new File([doc.output('blob')], doc_name + ".pdf", { type: "application/pdf" });
  var filesToShare = [pdf];

  try {
    navigator.share({ title: doc_name + ".pdf", files: filesToShare });
  } catch (error) {
    showBanner(error.message, bannerState.ERROR, ALERT_PARENT, ALERT_TIME);
  }
}

But I end up with this:

The name is correct on the title

enter image description here

But the pdf has a random name:

enter image description here

Any kind of help would be really appreciated!


Solution

  • I think this is more of an Android bug (or maybe intended behavior?) and not a problem with your code. I have reported this as a bug, so feel free to star to be notified of progress: https://crbug.com/1340850.