(onRecordingStateChange)
| 65 | * Initialize background-to-content message listeners |
| 66 | */ |
| 67 | export function initBackgroundCommunication(onRecordingStateChange) { |
| 68 | // Listen for recording state changes from background script |
| 69 | chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { |
| 70 | if (message.type === 'RECORDING_STATE_CHANGED') { |
| 71 | onRecordingStateChange(message.recording); |
| 72 | sendResponse({success: true}); |
| 73 | return true; |
| 74 | } |
| 75 | |
| 76 | if (message.type === 'CONTENT_SCRIPT_PING') { |
| 77 | sendResponse({ready: true}); |
| 78 | return true; |
| 79 | } |
| 80 | |
| 81 | if (message.type === 'GET_STORAGE_DATA') { |
| 82 | try { |
| 83 | const storageData = { |
| 84 | localStorage: {}, |
| 85 | sessionStorage: {} |
| 86 | }; |
| 87 | |
| 88 | // Extract localStorage |
| 89 | for (let i = 0; i < localStorage.length; i++) { |
| 90 | const key = localStorage.key(i); |
| 91 | storageData.localStorage[key] = localStorage.getItem(key); |
| 92 | } |
| 93 | |
| 94 | // Extract sessionStorage |
| 95 | for (let i = 0; i < sessionStorage.length; i++) { |
| 96 | const key = sessionStorage.key(i); |
| 97 | storageData.sessionStorage[key] = sessionStorage.getItem(key); |
| 98 | } |
| 99 | |
| 100 | sendResponse(storageData); |
| 101 | } catch (error) { |
| 102 | console.error('Error getting storage data:', error); |
| 103 | sendResponse({localStorage: {}, sessionStorage: {}}); |
| 104 | } |
| 105 | return true; |
| 106 | } |
| 107 | |
| 108 | if (message.type === 'GET_INITIAL_STATE') { |
| 109 | try { |
| 110 | // Capture comprehensive initial webpage state |
| 111 | const initialState = { |
| 112 | // Current URL |
| 113 | url: window.location.href, |
| 114 | |
| 115 | // Window dimensions (outer = includes browser chrome) |
| 116 | window: { |
| 117 | outerWidth: window.outerWidth, |
| 118 | outerHeight: window.outerHeight, |
| 119 | innerWidth: window.innerWidth, |
| 120 | innerHeight: window.innerHeight |
| 121 | }, |
| 122 | |
| 123 | // Scroll position |
| 124 | scroll: { |
no outgoing calls
no test coverage detected