Extension downloads files as "Unknown.txt"

Hello,

I am trying to download a file from the extension's settings page with the following code, but I cannot set the filename no matter what I try. It keeps downloading as Unknown.txt. The same code works well if I do it through a hosted page with an actual URL.

let downloadFile = function(contents, filename) {
	var element = document.createElement('a');
	element.setAttribute('href', 'data:application/octet-stream,' + encodeURIComponent(contents));
	element.setAttribute('download', filename);

	element.style.display = 'none';
	document.body.appendChild(element);

	element.click();

	document.body.removeChild(element);
}
downloadFile('test', 'file.txt');

Is this intended or a bug?

Extension downloads files as "Unknown.txt"
 
 
Q