|
6 | 6 |
|
7 | 7 | /** @typedef {import('./dbService.js').Session} Session */ |
8 | 8 |
|
9 | | -import { dbService } from './dbService.js'; |
| 9 | +import { dbService, getSchema, DB_VERSION } from './dbService.js'; |
10 | 10 |
|
11 | 11 | // Module-level properties |
12 | 12 | const debug = false; |
@@ -371,6 +371,59 @@ class SpacesService { |
371 | 371 | return [...(this.sessions || [])]; |
372 | 372 | } |
373 | 373 |
|
| 374 | + /** |
| 375 | + * Exports the entire database for debugging purposes with anonymized data. |
| 376 | + * @returns {Promise<Object>} Promise that resolves to an object containing: |
| 377 | + * - version: database version |
| 378 | + * - schema: database schema |
| 379 | + * - sessions: anonymized session data |
| 380 | + */ |
| 381 | + async exportDatabaseForDebugging() { |
| 382 | + await this.ensureInitialized(); |
| 383 | + |
| 384 | + const anonymizedSessions = (await dbService.fetchAllSessions()).map((session, index) => { |
| 385 | + const anonymizedSession = { ...session }; |
| 386 | + if (session.name) anonymizedSession.name = `Space_${index + 1}`; |
| 387 | + if (session.tabs && Array.isArray(session.tabs)) { |
| 388 | + anonymizedSession.tabs = session.tabs.map((tab, tabIndex) => |
| 389 | + this._anonymizeTab(tab, tabIndex + 1, 'Tab') |
| 390 | + ); |
| 391 | + } |
| 392 | + if (session.history && Array.isArray(session.history)) { |
| 393 | + anonymizedSession.history = session.history.map((historyTab, historyIndex) => |
| 394 | + this._anonymizeTab(historyTab, historyIndex + 1, 'History Tab') |
| 395 | + ); |
| 396 | + } |
| 397 | + return anonymizedSession; |
| 398 | + }); |
| 399 | + |
| 400 | + return { |
| 401 | + version: { |
| 402 | + database: DB_VERSION, |
| 403 | + extension: await this.fetchLastVersion(), |
| 404 | + manifest: chrome.runtime.getManifest().version |
| 405 | + }, |
| 406 | + schema: getSchema(), |
| 407 | + sessions: anonymizedSessions, |
| 408 | + }; |
| 409 | + } |
| 410 | + |
| 411 | + /** |
| 412 | + * Anonymizes a tab object for debugging export |
| 413 | + * @private |
| 414 | + * @param {Object} tab - The tab object to anonymize |
| 415 | + * @param {number} index - The index number for generating unique placeholder values |
| 416 | + * @param {string} prefix - The prefix for the title (e.g., 'Tab' or 'History Tab') |
| 417 | + * @returns {Object} Anonymized tab object |
| 418 | + */ |
| 419 | + _anonymizeTab(tab, index, prefix) { |
| 420 | + const anonymizedTab = { ...tab }; |
| 421 | + if (tab.url) anonymizedTab.url = `https://example-${index}.com/path`; |
| 422 | + if (tab.title) anonymizedTab.title = `${prefix} ${index}`; |
| 423 | + if (tab.favIconUrl) anonymizedTab.favIconUrl = 'data:anonymized-favicon'; |
| 424 | + return anonymizedTab; |
| 425 | + } |
| 426 | + |
374 | 427 | /** |
375 | 428 | * Find a session by windowId, checking both in-memory sessions and database |
376 | 429 | * @param {number} windowId - The window ID to search for |
|
0 commit comments