(trackingLog)
| 53 | * Capture comprehensive auth data from all domains visited during recording |
| 54 | */ |
| 55 | export async function captureComprehensiveAuthData(trackingLog) { |
| 56 | const domainData = new Map(); |
| 57 | const visitedDomains = new Set(); |
| 58 | |
| 59 | try { |
| 60 | // Extract unique domains from tracking log |
| 61 | for (const action of trackingLog) { |
| 62 | if (action.url) { |
| 63 | try { |
| 64 | const url = new URL(action.url); |
| 65 | visitedDomains.add(url.hostname); |
| 66 | } catch (e) { |
| 67 | // Skip invalid URLs |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | console.log('Collecting auth data for domains:', Array.from(visitedDomains)); |
| 73 | |
| 74 | // Collect data for each unique domain |
| 75 | for (const domain of visitedDomains) { |
| 76 | const data = { |
| 77 | origins: [], |
| 78 | cookies: [] |
| 79 | }; |
| 80 | |
| 81 | try { |
| 82 | // Get all cookies for this domain and its subdomains |
| 83 | const cookies = await chrome.cookies.getAll({ domain: domain }); |
| 84 | data.cookies = cookies.map(cookie => ({ |
| 85 | name: cookie.name, |
| 86 | value: cookie.value, |
| 87 | domain: cookie.domain, |
| 88 | path: cookie.path || '/', |
| 89 | secure: !!cookie.secure, |
| 90 | httpOnly: !!cookie.httpOnly, |
| 91 | sameSite: mapSameSite(cookie.sameSite), |
| 92 | expirationDate: cookie.expirationDate |
| 93 | })); |
| 94 | |
| 95 | // For HTTPS domains, also collect localStorage |
| 96 | try { |
| 97 | const origin = `https://${domain}`; |
| 98 | |
| 99 | // Try to get a tab with this domain to collect localStorage |
| 100 | const tabs = await chrome.tabs.query({ url: `*://${domain}/*` }); |
| 101 | if (tabs.length > 0) { |
| 102 | const storageData = await chrome.tabs.sendMessage(tabs[0].id, { |
| 103 | type: 'GET_STORAGE_DATA' |
| 104 | }).catch(() => ({ localStorage: {}, sessionStorage: {} })); |
| 105 | |
| 106 | data.origins.push({ |
| 107 | origin, |
| 108 | localStorage: storageData.localStorage || {} |
| 109 | }); |
| 110 | } else { |
| 111 | // No active tab, just add empty localStorage for this origin |
| 112 | data.origins.push({ |
no test coverage detected