Search code examples
javascriptopera

Does not download the file when i click secondly in Opera


I try to download the file that came from API in Opera Browser.

The file is downloaded on the first click, it's okay but does not download after click the second time(actually more than one). No errors, just I cannot see the downloaded file. So, it does not download the file.

Shortly, the file is downloaded only first click. Why it does not download in after subsequent clicks?

Also, The file is downloaded on every click in Chrome and Mozilla, this works. I'm just having this error in Opera.

My Codes;

function downloadFile(response: Response) {
  const fileName = getFileNameFromHttpResponse(response);
  const newBlob = new Blob([<any>response.body],{ type: (<any>response.body).type });
  if (window.navigator && window.navigator.msSaveOrOpenBlob) {
    window.navigator.msSaveOrOpenBlob(newBlob);
    return;
  }
  const data = window.URL.createObjectURL(newBlob);

  const link = document.createElement('a');
  link.href = data;
  link.download = fileName;
  link.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }));
  setTimeout(() => {
    window.URL.revokeObjectURL(data);
  }, 100);
}

About Opera: Version:65.0.3467.48 System:Windows 10 64-bit

How to fix this?

Thanks.


Solution

  • Solved my problem. Opera refusing to my download request. I set the "Automatic Downloads" to as "Allow" and it's worked.