Currently, I am in the process of developing an Angular8 PWA and have successfully implemented webshare to share text content. To my excitement, Chrome has now extended its support for file sharing starting from May 2019.
However, while attempting to integrate file sharing in Typescript, I encountered a challenging error:
Error: NotAllowedError - Permission denied
let navigator: any;
navigator = window.navigator;
const title = "myTitle";
let data = {
title: title,
text: text,
url: url,
files: []
};
console.log(data);
if (navigator.share) {
fetch(url)
.then(res => res.blob())
.then(file => {
const fileName = data.text + ".mp3";
const options = { type: "audio/mp3" };
const newFile = new File([file], fileName, options);
data.files.push(newFile);
console.log(data);
//lastModified: 1564912016680
//lastModifiedDate: Sun Aug 04 2019 11:46:56 GMT+0200 (Central European //Summer Time) {}
//name: "myName.mp3"
//size: 40643
//type: "audio/mpeg"
//webkitRelativePath: ""
if (navigator.canShare(data)) {
navigator
.share(data)
.then(() => {})
.catch(err => {
console.error("Unsuccessful share " + err.message); //Here is where I encounter the Permissions denied error
});
}
});
I'm uncertain whether the issue lies with how I retrieve the file (which seems correct) or with the canShare method call. I'm using Chrome on my mobile device. The provided fiddle functions properly on my phone, although it requires selecting a file. https://jsfiddle.net/ericwilligers/8cpuskqd/
The share functionality is connected to a button containing the link of the file to be shared.
Edit
Upon converting data.files from an array to an object, a new error message surfaces:
Error: TypeError - Failed to execute 'canShare' on 'Navigator': Iterator getter is not callable.
Edit2
To replicate the problem, I have created a codepen: