A Chrome MV3 extension that exports a full ChatGPT history to JSON in the shape of ChatGPT's own conversations.json, for the Amgreat Gemini migration tool. Everything runs in the user's browser against their own session. Batches of 25 per file, downloaded through the service worker because Chrome blocks multiple page-initiated downloads. Adaptive pacing with 429 backoff, Retry-After support, token refresh and localStorage resume.
27 lines
1.1 KiB
JavaScript
27 lines
1.1 KiB
JavaScript
/* Service worker: performs downloads via the extension's own downloads API.
|
|
*
|
|
* A content script (page context) may auto-download only ONE file before Chrome
|
|
* blocks the rest behind a "multiple downloads" guard. Routing each batch
|
|
* through chrome.downloads here sidesteps that: every part downloads
|
|
* immediately and appears in Chrome's download tray.
|
|
*
|
|
* Service workers cannot call URL.createObjectURL, so the content script makes
|
|
* the blob URL and sends it here. A data: URL is accepted as a fallback for the
|
|
* same reason, though large ones are less reliable — hence blob first.
|
|
*/
|
|
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
|
|
if (!msg || msg.type !== 'download' || !msg.url) return;
|
|
try {
|
|
chrome.downloads.download(
|
|
{ url: msg.url, filename: msg.filename, saveAs: false, conflictAction: 'uniquify' },
|
|
function (id) {
|
|
var err = chrome.runtime.lastError;
|
|
sendResponse({ ok: !err && id != null, error: err && err.message });
|
|
}
|
|
);
|
|
} catch (e) {
|
|
sendResponse({ ok: false, error: String(e) });
|
|
}
|
|
return true; // keep the message channel open for the async sendResponse
|
|
});
|