(initialState, currentTab)
| 45 | * This sets the baseline for the recording |
| 46 | */ |
| 47 | export function createInitialActions(initialState, currentTab) { |
| 48 | if (!initialState) { |
| 49 | console.warn('⚠️ No initial state provided, skipping initial actions'); |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | console.log('🎬 Creating initial actions from state...'); |
| 54 | |
| 55 | // 1. Initial URL - Always add this first |
| 56 | if (currentTab && currentTab.url) { |
| 57 | actions.push({ |
| 58 | browserAction: ACTION_TYPES.GO_TO_URL, |
| 59 | url: currentTab.url, |
| 60 | timestamp: Date.now() |
| 61 | }); |
| 62 | console.log(`📍 Initial URL: ${currentTab.url}`); |
| 63 | } |
| 64 | |
| 65 | // 2. Window dimensions - Set baseline |
| 66 | if (initialState.window) { |
| 67 | dimension_w = initialState.window.outerWidth; |
| 68 | dimension_h = initialState.window.outerHeight; |
| 69 | |
| 70 | // Add resize action to set initial window size |
| 71 | actions.push({ |
| 72 | browserAction: ACTION_TYPES.WINDOW_RESIZE, |
| 73 | width: dimension_w, |
| 74 | height: dimension_h, |
| 75 | timestamp: Date.now() |
| 76 | }); |
| 77 | console.log(`📐 Initial window size: ${dimension_w}x${dimension_h}`); |
| 78 | } |
| 79 | |
| 80 | // 3. Scroll position - Only add if page is scrolled |
| 81 | if (initialState.scroll) { |
| 82 | scroll_top = initialState.scroll.y; |
| 83 | scroll_left = initialState.scroll.x; |
| 84 | |
| 85 | // Only add scroll action if page is not at top-left |
| 86 | if (scroll_top > 0 || scroll_left > 0) { |
| 87 | actions.push({ |
| 88 | browserAction: ACTION_TYPES.WINDOW_SCROLL, |
| 89 | scrollPosition: { |
| 90 | x: scroll_left, |
| 91 | y: scroll_top |
| 92 | }, |
| 93 | documentSize: initialState.document, |
| 94 | viewportSize: initialState.viewport, |
| 95 | timestamp: Date.now() |
| 96 | }); |
| 97 | console.log(`📜 Initial scroll position: (${scroll_left}, ${scroll_top})`); |
| 98 | } else { |
| 99 | console.log('📜 Page at top - no initial scroll needed'); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | console.log(`✅ Created ${actions.length} initial action(s)`); |
| 104 | } |
no outgoing calls
no test coverage detected