Ka-Note/ka-note/debug-idb3.mjs

72 lines
2.6 KiB
JavaScript

import { chromium } from 'playwright';
const userDataDir = 'C:/Users/d-chrka/AppData/Local/Google/Chrome/User Data';
const context = await chromium.launchPersistentContext(userDataDir, {
headless: false,
channel: 'chrome',
args: ['--profile-directory=Default']
});
const page = await context.newPage();
await page.goto('http://localhost:5173');
await page.waitForTimeout(4000);
// List DBs
const dbs = await page.evaluate(() => indexedDB.databases());
console.log('Databases:', JSON.stringify(dbs));
// Dump historyEntries
const historyResult = await page.evaluate(() => {
return new Promise((resolve) => {
const request = indexedDB.open('KaNoteDB');
request.onsuccess = (e) => {
const db = e.target.result;
const storeNames = Array.from(db.objectStoreNames);
if (!storeNames.includes('historyEntries')) {
resolve({ error: 'no historyEntries', stores: storeNames, version: db.version });
return;
}
const tx = db.transaction('historyEntries', 'readonly');
const store = tx.objectStore('historyEntries');
const all = store.getAll();
all.onsuccess = () => {
const matched = all.result.filter(e => e.text && e.text.includes('['));
resolve({ total: all.result.length, matched: matched.map(e => ({ id: e.id, text: e.text })) });
};
};
request.onerror = (e) => resolve({ error: String(e.target.error) });
});
});
console.log('\n=== HISTORY ENTRIES ===');
console.log('Total:', historyResult.total, '| Matched:', historyResult.matched?.length);
if (historyResult.error) console.log('ERROR:', historyResult.error, historyResult.stores);
(historyResult.matched || []).forEach(e => console.log('ID:', e.id, '\nTEXT:', JSON.stringify(e.text), '\n'));
// Dump tasks
const tasksResult = await page.evaluate(() => {
return new Promise((resolve) => {
const request = indexedDB.open('KaNoteDB');
request.onsuccess = (e) => {
const db = e.target.result;
const storeNames = Array.from(db.objectStoreNames);
if (!storeNames.includes('tasks')) {
resolve({ error: 'no tasks store', stores: storeNames });
return;
}
const tx = db.transaction('tasks', 'readonly');
const store = tx.objectStore('tasks');
const all = store.getAll();
all.onsuccess = () => resolve({ tasks: all.result });
};
request.onerror = (e) => resolve({ error: String(e.target.error) });
});
});
console.log('\n=== TASKS ===');
if (tasksResult.error) console.log('ERROR:', tasksResult.error, '| Stores:', tasksResult.stores);
else console.log(JSON.stringify(tasksResult.tasks, null, 2));
await context.close();