Skip to content

Commit e97830b

Browse files
committed
added more logs, investigating content scripts and background
1 parent ee23309 commit e97830b

File tree

6 files changed

+19
-7
lines changed

6 files changed

+19
-7
lines changed

src/app/components/Diff.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ function Diff(props: DiffProps): JSX.Element {
8989
console.log('html: ', html);
9090

9191
console.log(show);
92+
console.log(formatters.html.showUnchanged());
9293
if (show)
9394
formatters.html.showUnchanged(); // shows unchanged values if we're on the '/diffRaw' path
9495
else formatters.html.hideUnchanged(); // hides unchanged values

src/app/components/StateRoute/History.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function History(props: Record<string, unknown>): JSX.Element {
3737

3838
const svgRef = React.useRef(null);
3939
const root = JSON.parse(JSON.stringify(hierarchy)); // why do we stringify and then parse our hierarchy back to JSON? (asked 7/31/23)
40-
40+
console.log('history root: ', root);
4141
// setting the margins for the Map to render in the tab window.
4242
const innerWidth: number = totalWidth - margin.left - margin.right;
4343
const innerHeight: number = totalHeight - margin.top - margin.bottom - 60;
@@ -167,14 +167,15 @@ function History(props: Record<string, unknown>): JSX.Element {
167167
const makeD3Tree = () => {
168168
const svg = d3.select(svgRef.current); // d3.select Selects the first element/node that matches svgRef.current. If no element/node match returns an empty selection. If multiple elements/nodes match the selector, only the first matching element/node (in document order) will be selected.
169169
svg.selectAll('*').remove(); // Selects all elements. The elements will be selected in document order (top-to-bottom). We then remove the selected elements/nodes from the DOM. This is important as to ensure that the SVG is empty before rendering the D3 based visualization to avoid interference/overlap with any previously rendered content.
170-
170+
console.log('makeD3Tree initial svgRef: ', svgRef);
171171
const tree = (data) => {
172172
// function that takes in data and turns it into a d3 tree.
173173
const treeRoot = d3.hierarchy(data); // 'd3.hierarchy' constructs a root node from the specified hierarchical data.
174174
return d3.tree().size([innerWidth, innerHeight])(treeRoot); // d3.tree creates a new tree layout with a size option of innerWidth (~line 41) and innerHeight (~line 42). We specify our new tree layout's root as 'treeRoot' which assigns an x and y property to each node to represent an [x, y] coordinate system.
175175
};
176176

177177
const d3root = tree(root); // create a d3. tree from our root
178+
console.log('d3root: ', d3root);
178179
const currNode = labelCurrentNode(d3root); // iterate through our nodes and apply a color property
179180

180181
const g = svg //serves as a container for the nodes and links within the D3 Visualization of the tree
@@ -306,12 +307,13 @@ function History(props: Record<string, unknown>): JSX.Element {
306307
};
307308

308309
useEffect(() => {
310+
console.log('currLocation: ', currLocation);
309311
makeD3Tree();
310-
}, [root, currLocation]); // if the 'root' or 'currLocation' changes, re-build the D3 Tree
312+
}, [root /*, currLocation*/]); // if the 'root' or 'currLocation' changes, re-build the D3 Tree
311313

312-
useEffect(() => {
313-
dispatch(setCurrentTabInApp('history')); // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'webmetrics' to facilitate render.
314-
}, []);
314+
// useEffect(() => {
315+
// dispatch(setCurrentTabInApp('history')); // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'webmetrics' to facilitate render.
316+
// }, []);
315317

316318
// then rendering each node in History tab to render using D3, which will share area with LegendKey
317319
return (

src/app/slices/mainSlice.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export const mainSlice = createSlice({
4141
const { tabs, currentTab, port } = state;
4242

4343
port.postMessage({ action: 'emptySnap', tabId: currentTab }); //communicate with background.js (service worker)
44-
44+
console.log('emptySnapshots tabs: ', tabs);
45+
console.log('emptySnapshots currentTab: ', currentTab);
4546
// properties associated with timetravel + seek bar
4647
tabs[currentTab].sliderIndex = 0;
4748
tabs[currentTab].viewIndex = 0;

src/backend/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ linkFiber();
4040
* 3. If not navigate during jumping => invoke timeJump to update ReactFiber tree with cached data from the snapshot payload
4141
*/
4242
window.addEventListener('message', async ({ data: { action, payload } }: MsgData) => {
43+
console.log('index.ts window event listener data received: ', action, payload);
4344
switch (action) {
4445
case 'jumpToSnap':
4546
// Set mode to jumping to prevent snapShot being sent to frontEnd

src/extension/background.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ chrome.runtime.onConnect.addListener((port) => {
185185
if (portsArr[i] === e) {
186186
portsArr.splice(i, 1);
187187
chrome.runtime.sendMessage('portDisconnect');
188+
console.log(`port ${e} disconnected. Remaining portsArr: `, portsArr);
188189
break;
189190
}
190191
}
@@ -262,6 +263,7 @@ chrome.runtime.onConnect.addListener((port) => {
262263

263264
// background.js listening for a message from contentScript.js
264265
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
266+
console.log('background.js received message with action: ', request.action);
265267
// AUTOMATIC MESSAGE SENT BY CHROME WHEN CONTENT SCRIPT IS FIRST LOADED: set Content
266268
if (request.type === 'SIGN_CONNECT') {
267269
return true;
@@ -291,6 +293,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
291293
// everytime we get a new tabId, add it to the object
292294
if (isReactTimeTravel && !(tabId in tabsObj)) {
293295
tabsObj[tabId] = createTabObj(tabTitle);
296+
console.log('tabsObj after createTabObj function call: ', tabsObj);
294297
}
295298

296299
switch (action) {
@@ -300,6 +303,8 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
300303
break;
301304
}
302305
case 'jumpToSnap': {
306+
console.log(`background.js received jumpToSnap from UI at ${Date.now().toLocaleString()}`);
307+
console.log('portsArr at time of jumpToSnap in backgroundjs: ', portsArr);
303308
changeCurrLocation(tabsObj[tabId], tabsObj[tabId].hierarchy, index, name);
304309
if (portsArr.length > 0) {
305310
portsArr.forEach((bg) =>
@@ -455,6 +460,7 @@ chrome.tabs.onActivated.addListener((info) => {
455460
// never set a reactime instance to the active tab
456461
if (!tab.pendingUrl?.match('^chrome-extension')) {
457462
activeTab = tab;
463+
console.log('activeTab: ', activeTab);
458464
if (portsArr.length > 0) {
459465
portsArr.forEach((bg) =>
460466
bg.postMessage({

src/extension/contentScript.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ window.addEventListener('message', (msg) => {
1515
// recorded on the test application from backend files (linkFiber.ts).
1616
// Background.js has a listener that includes switch cases, depending on
1717
// the name of the action (e.g. 'tabReload').
18+
console.log('message sent to window event listener: ', msg.data);
1819
if (firstMessage) {
1920
// One-time request tells the background script that the tab has reloaded.
2021
chrome.runtime.sendMessage({ action: 'tabReload' });

0 commit comments

Comments
 (0)