Skip to content

Resave error #30

@Antiever

Description

@Antiever

Previously, I used the extension all the time to edit previously saved mht files, but on the latest versions, the save file window doesn't appear.

Error log

chrome.action.onClicked.addListener(function (tab) {
    saveTab(tab);
});
chrome.runtime.onInstalled.addListener(function () {
    chrome.contextMenus.create({
        id: 'save-mht',
        title: 'Save as .mht...',
        contexts: ['all'],
    });
});
chrome.contextMenus.onClicked.addListener(function (info, tab) {
    if (info.menuItemId == 'save-mht') {
        saveTab(tab);
    }
});
async function saveTab(tab) {
    chrome.downloads.download({
        conflictAction: 'prompt',
        filename: `${sanitizeFilename(tab.title)}.mht`,
        saveAs: true,
        url: await captureTabToDataUrl(tab.id),
    });
}
function sanitizeFilename(filename) {
    return filename.replace(/[<>:"/\\|?*\x00-\x1F~]/g, '_');
}
async function captureTabToDataUrl(tabId) {
    const tabText = await new Promise(function (resolve, reject) {
        chrome.pageCapture.saveAsMHTML({ tabId }, function (mhtmlData) {
            return mhtmlData
                ? resolve(mhtmlData.text())
                : reject(new Error(chrome.runtime.lastError.message));  <------ error
        });
    });
    return `data:multipart/related;base64,${btoa(tabText)}`;
}
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
    if (changeInfo.status != 'loading') {
        return;
    }
    setPopup(tabId, tab.url);
});
chrome.tabs.query({}).then(function (tabs) {
    tabs.forEach(function (tab) {
        setPopup(tab.id, tab.url);
    });
});
async function setPopup(tabId, url) {
    if (!/^file:\/\/\/.*\.mht(ml)?$/i.test(url)) {
        return;
    }
    const { text, popup } = (await chrome.permissions.contains({ origins: ['file:///*'] }))
        ? { text: '🛈', popup: 'mht-info.html' }
        : { text: '⚠', popup: 'file-permission.html' };
    chrome.action.setBadgeText({ tabId, text });
    chrome.action.setPopup({ tabId, popup });
}
export {};
//# sourceMappingURL=worker.js.map

Permissions to work with local files are granted

chrome_anG0ZF0wkI

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions