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

Resave error #30

Open
Antiever opened this issue Aug 4, 2024 · 4 comments
Open

Resave error #30

Antiever opened this issue Aug 4, 2024 · 4 comments

Comments

@Antiever
Copy link

Antiever commented Aug 4, 2024

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

@vsDizzy
Copy link
Owner

vsDizzy commented Aug 10, 2024

Thanks for reporting this. I am able to reproduce this.
The actual error is

Error: Don't have permissions required to capture this page.

This is something that is changed in Chrome permissions.

As a workaround you can currently use "save as..." in the context menu,
image

@Antiever
Copy link
Author

Antiever commented Aug 10, 2024

Thank you.
AFAIK "save as" can't save page edited with devtools, it's just grab original code :(
Can you specify the version of chrome from which this limitation appeared?

@vsDizzy
Copy link
Owner

vsDizzy commented Aug 10, 2024

I'm not sure. I see it has been reported since 2019.
brian-girko/save-as-mhtml#4
Also this
https://www.google.com/search?q=%22Don%27t+have+permissions+required+to+capture+this+page.%22

@vsDizzy
Copy link
Owner

vsDizzy commented Aug 13, 2024

I opened Chromium ticket

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