SaveAsMHT icon indicating copy to clipboard operation
SaveAsMHT copied to clipboard

Error : Cannot Save Google Scholar Page

Open bsplu opened this issue 3 years ago • 3 comments

The extension works well, but I found one case failed.

When I clicked the button for saving a page from Google Scholar (i.e. https://scholar.google.com/citations?user=vuJL4QwAAAAJ&hl=en), there was no response and nothing happened.

I checked the background page of the extension. It shows the error : 'Unchecked runtime.lastError: Invalid filename'.

screenshot

bsplu avatar Sep 02 '21 07:09 bsplu

Using

      const a = document.createElement('a')
      a.download = filename
      a.href = URL.createObjectURL(blob)
      a.click()
      setTimeout(() => URL.revokeObjectURL(a.href), 5000)

instead of https://github.com/vsDizzy/SaveAsMHT/blob/524c606aec57378740ebd470b2edc3a077815dac/extension/background.js#L11-L16 correctly saves the file.

AlttiRi avatar Sep 30 '21 14:09 AlttiRi

The alternative fix:

  function download(filename, blob) {
    chrome.downloads.download({
      conflictAction: 'prompt',
      filename: filename,
      saveAs: true,
      url: URL.createObjectURL(blob),
    }, downloadId => {
      if (downloadId === undefined) {
        const a = document.createElement('a')
        a.download = filename
        a.href = URL.createObjectURL(blob)
        a.click()
        setTimeout(() => URL.revokeObjectURL(a.href), 5000)
      }
    })
  }

Or

  function download(filename, blob) {
    chrome.downloads.download({
      conflictAction: 'prompt',
      filename: filename,
      saveAs: true,
      url: URL.createObjectURL(blob),
    }, downloadId => {
      const lastError = chrome.runtime.lastError
      if (lastError) {
        console.log(lastError.message, filename)
        const a = document.createElement('a')
        a.download = filename
        a.href = URL.createObjectURL(blob)
        a.click()
        setTimeout(() => URL.revokeObjectURL(a.href), 5000)
      }
    })
  }

AlttiRi avatar Sep 30 '21 15:09 AlttiRi

There are some invisible characters in the site title

  • ‪Chen Ning Yang, 杨振宁‬ - ‪Google Scholar‬

The result file name is

  • [scholar.google.com] 2021.09.30—_Chen Ning Yang, 杨振宁_ - _Google Scholar_.mht

(with this feature https://github.com/vsDizzy/SaveAsMHT/issues/25)

AlttiRi avatar Sep 30 '21 15:09 AlttiRi