SaveAsMHT
SaveAsMHT copied to clipboard
Error : Cannot Save Google Scholar Page
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'.
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.
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)
}
})
}
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)