Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error : Cannot Save Google Scholar Page #24

Open
bsplu opened this issue Sep 2, 2021 · 3 comments
Open

Error : Cannot Save Google Scholar Page #24

bsplu opened this issue Sep 2, 2021 · 3 comments

Comments

@bsplu
Copy link

bsplu commented Sep 2, 2021

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

@AlttiRi
Copy link

AlttiRi commented Sep 30, 2021

Using

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

instead of

chrome.downloads.download({
conflictAction: 'prompt',
filename: filename,
saveAs: true,
url: URL.createObjectURL(blob),
})

correctly saves the file.

@AlttiRi
Copy link

AlttiRi commented Sep 30, 2021

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
Copy link

AlttiRi commented Sep 30, 2021

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 #25)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants