Skip to content

Commit 498385d

Browse files
fix bug
1 parent 55597f6 commit 498385d

4 files changed

Lines changed: 54 additions & 9 deletions

File tree

src/app/containers/MainContainer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ function MainContainer(): JSX.Element {
7777
break;
7878
}
7979
case 'sendSnapshots': {
80-
dispatch(setTab(payload));
80+
// sourceTab is the tab that sent the snapshot; setTab expects tabId, not tabsObj
81+
if (typeof sourceTab === 'number') dispatch(setTab(sourceTab));
8182
dispatch(addNewSnapshots(payload));
8283
break;
8384
}

src/app/slices/mainSlice.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,14 @@ export const mainSlice = createSlice({
5050
const currSnapshot = tabs[currentTab].snapshots[tabs[currentTab].currLocation.index]; // current snapshot
5151
const currAxSnapshot = tabs[currentTab].axSnapshots[tabs[currentTab].currLocation.index]; // current accessibility tree snapshot
5252

53-
tabs[currentTab].hierarchy.stateSnapshot = { ...currSnapshot }; // resets hierarchy to current snapshot
53+
// Strip lastUserEvent so jumpToSnap (from changeSlider) won't re-show the pointer
54+
const cleanSnapshot = { ...currSnapshot };
55+
delete (cleanSnapshot as { lastUserEvent?: unknown }).lastUserEvent;
56+
57+
tabs[currentTab].hierarchy.stateSnapshot = { ...cleanSnapshot }; // resets hierarchy to current snapshot
5458
tabs[currentTab].hierarchy.axSnapshot = { ...currAxSnapshot }; // resets hierarchy to current accessibility tree snapshot
5559
tabs[currentTab].hierarchy.children = []; // resets hierarchy
56-
tabs[currentTab].snapshots = [currSnapshot]; // resets snapshots to current snapshot
60+
tabs[currentTab].snapshots = [cleanSnapshot]; // resets snapshots to current snapshot (no lastUserEvent)
5761
tabs[currentTab].axSnapshots = [currAxSnapshot]; // resets snapshots to current snapshot
5862

5963
// resets currLocation to current snapshot
@@ -200,19 +204,21 @@ export const mainSlice = createSlice({
200204
const { port, currentTab, tabs } = state;
201205
const { hierarchy, snapshots } = tabs[currentTab] || {};
202206

203-
// finds the name by the action.payload parsing through the hierarchy to send to background.js the current name in the jump action
204-
const nameFromIndex = findName(action.payload, hierarchy);
205-
// nameFromIndex is a number based on which jump button is pushed
207+
const index = typeof action.payload === 'object' ? action.payload.index : action.payload;
208+
209+
// finds the name by the index parsing through the hierarchy to send to background.js the current name in the jump action
210+
const nameFromIndex = findName(index, hierarchy);
206211

212+
// Always pass full snapshot so laser pointer shows when snapshot has lastUserEvent
207213
port.postMessage({
208214
action: 'jumpToSnap',
209-
payload: snapshots[action.payload],
210-
index: action.payload,
215+
payload: snapshots[index],
216+
index,
211217
name: nameFromIndex,
212218
tabId: currentTab,
213219
});
214220

215-
tabs[currentTab].sliderIndex = action.payload;
221+
tabs[currentTab].sliderIndex = index;
216222
},
217223

218224
setCurrentTabInApp: (state, action) => {

src/extension/background.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,12 @@ chrome.runtime.onConnect.addListener(async (port) => {
512512
tabsObj[tabId].currBranch = 1; // reset currBranch
513513
tabsObj[tabId].currLocation = tabsObj[tabId].hierarchy; // reset currLocation
514514

515+
// Hide click-replay visualization since snapshots were cleared
516+
try {
517+
chrome.tabs.sendMessage(tabId, { action: 'hideClickReplay' });
518+
} catch (err) {
519+
// Tab may be closed or content script not loaded
520+
}
515521
return true; // return true so that port remains open
516522

517523
case 'setPause': // Pause = lock on tab
@@ -733,6 +739,12 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
733739
);
734740
}
735741

742+
// User action created new snapshot; hide click-replay visualization
743+
try {
744+
chrome.tabs.sendMessage(sourceTab, { action: 'hideClickReplay' });
745+
} catch (err) {
746+
/* tab may be closed */
747+
}
736748
break;
737749
}
738750

@@ -756,15 +768,29 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
756768

757769
if (isDuplicateSnapshot(previousSnap, incomingSnap)) {
758770
console.warn('Duplicate snapshot detected, skipping');
771+
// Still hide pointer - user interaction triggered a snapshot even if we skipped it
772+
try {
773+
chrome.tabs.sendMessage(sourceTab, { action: 'hideClickReplay' });
774+
} catch (err) {
775+
/* tab may be closed */
776+
}
759777
break;
760778
}
761779

762780
// Or if it is a snapShot after a jump, we don't record it.
781+
let didAddSnapshot = false;
763782
if (reloaded[tabId]) {
764783
// don't add anything to snapshot storage if tab is reloaded for the initial snapshot
765784
reloaded[tabId] = false;
785+
// Still hide pointer - snapshot after jump, user has moved on
786+
try {
787+
chrome.tabs.sendMessage(sourceTab, { action: 'hideClickReplay' });
788+
} catch (err) {
789+
/* tab may be closed */
790+
}
766791
} else {
767792
tabsObj[tabId].snapshots.push(request.payload);
793+
didAddSnapshot = true;
768794
// INVOKING buildHierarchy FIGURE OUT WHAT TO PASS IN
769795
if (!tabsObj[tabId][index]) {
770796
// check if accessibility recording has been toggled on
@@ -799,6 +825,15 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
799825
} else {
800826
console.warn('No active ports to send snapshots to.');
801827
}
828+
829+
// User action created new snapshot; hide click-replay visualization
830+
if (didAddSnapshot) {
831+
try {
832+
chrome.tabs.sendMessage(sourceTab, { action: 'hideClickReplay' });
833+
} catch (err) {
834+
/* tab may be closed */
835+
}
836+
}
802837
}
803838
default:
804839
break;

src/extension/contentScript.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ chrome.runtime.onMessage.addListener((request) => {
281281
// '*' == target window origin required for event to be dispatched, '*' = no preference
282282
window.postMessage(request, '*');
283283
}
284+
if (action === 'hideClickReplay') {
285+
updateClickReplayPointer(undefined);
286+
}
284287
if (action === 'portDisconnect' && !currentPort && !isAttemptingReconnect) {
285288
console.log('Received disconnect message, initiating reconnection');
286289
// When we receive a port disconnection message, relay it to the window

0 commit comments

Comments
 (0)