(trackingLog, initialState = null)
| 107 | * Process and send track data to backend |
| 108 | */ |
| 109 | export async function processAndSendTrack(trackingLog, initialState = null) { |
| 110 | console.log('processAndSendTrack called with actionOnlyMode:', actionOnlyMode); |
| 111 | |
| 112 | // Check if we're in action only mode |
| 113 | if (actionOnlyMode) { |
| 114 | console.log('Action only mode ACTIVE - processAndSendTrack called but skipping backend submission'); |
| 115 | console.log('Current actionOnlyMode value:', actionOnlyMode); |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | console.log('Action only mode NOT active - proceeding with backend submission'); |
| 120 | |
| 121 | try { |
| 122 | // Use all actions (no filtering needed) |
| 123 | const actualActions = trackingLog; |
| 124 | |
| 125 | // Validate and fix XPath issues before sending |
| 126 | const fixedLog = actualActions.map(action => { |
| 127 | // First validate and clean the action |
| 128 | let fixedAction = validateActionXPath({...action}); |
| 129 | |
| 130 | // Then fix XPath quote issues for Python compatibility |
| 131 | if (fixedAction.xpath) { |
| 132 | const xpathArray = Array.isArray(fixedAction.xpath) ? |
| 133 | fixedAction.xpath : [fixedAction.xpath]; |
| 134 | |
| 135 | fixedAction.xpath = xpathArray.map(xpath => fixXpathDoubleQuoteIssues(xpath)); |
| 136 | } |
| 137 | |
| 138 | return fixedAction; |
| 139 | }); |
| 140 | |
| 141 | console.log('Sending recording with', fixedLog.length, 'actions'); |
| 142 | |
| 143 | // Send to backend and handle redirect (no popup) - pass actionOnlyMode as failsafe and initialState |
| 144 | await sendTrackToBackend(fixedLog, null, actionOnlyMode, initialState); |
| 145 | } catch (error) { |
| 146 | console.error('Error in processAndSendTrack:', error); |
| 147 | |
| 148 | // Show user-friendly error notification |
| 149 | chrome.notifications.create({ |
| 150 | type: 'basic', |
| 151 | iconUrl: chrome.runtime.getURL('icons/icon-48.png'), |
| 152 | title: 'Recording Processing Failed', |
| 153 | message: 'Unable to process recording. Please try again.', |
| 154 | priority: 2 |
| 155 | }); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Start a fresh recording session |
no test coverage detected