Skip to content

Commit f302674

Browse files
committed
added MORE console logs and made them more semantic
1 parent 348ab01 commit f302674

File tree

5 files changed

+95
-28
lines changed

5 files changed

+95
-28
lines changed

src/app/components/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function App(): JSX.Element {
1515
<ThemeProvider theme={theme}>
1616
<Router>
1717
{/* we wrap our application with the <Router> tag so that all components that are nested will have the react-router context */}
18+
{console.log('App reloaded')}
1819
<MainContainer />
1920
</Router>
2021
</ThemeProvider>

src/app/containers/ErrorContainer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ function ErrorContainer(): JSX.Element {
4949

5050
// hook that sets timer while waiting for a snapshot from the background script, resets if the tab changes/reloads
5151
useEffect(() => {
52-
if (tabs[currentTab]) console.log('ErrorContainer useEffect fired, ', tabs[currentTab].status);
52+
if (tabs[currentTab])
53+
console.log('ErrorContainer useEffect fired, ', JSON.stringify(tabs[currentTab]?.status));
5354
// We declare a function
5455
function setLoadingArray(i: number, value: boolean) {
5556
// 'setLoadingArray' checks an element in our 'loadingArray' local state and compares it with passed in boolean argument. If they don't match, we update our local state replacing the selected element with the boolean argument

src/app/containers/MainContainer.tsx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ function MainContainer(): JSX.Element {
3939
);
4040
//JR: check connection status
4141
const { connectionStatus }: MainState = useSelector((state: RootState) => state.main);
42-
console.log('MainContainer connectionStatus at initialization: ', connectionStatus);
42+
43+
// JR 12.22.23: so far this log always returns true
44+
//console.log('MainContainer connectionStatus at initialization: ', connectionStatus);
4345

4446
const [actionView, setActionView] = useState(true); // We create a local state 'actionView' and set it to true
4547

@@ -70,18 +72,24 @@ function MainContainer(): JSX.Element {
7072
};
7173

7274
// Function to listen for a message containing snapshots from the /extension/build/background.js service worker
73-
const messageListener = (message: {
75+
const messageListener = ({
76+
action,
77+
payload,
78+
sourceTab,
79+
}: {
7480
action: string;
7581
payload: Record<string, unknown>;
7682
sourceTab: number;
7783
}) => {
78-
const { action, payload, sourceTab } = message;
84+
// const { action, payload, sourceTab } = message;
7985
let maxTab: number;
86+
8087
console.log(
81-
'MainContainer messageListener message. action: ',
88+
'MainContainer received message inside of the port messageListener. action: ',
8289
action,
8390
'payload: ',
84-
JSON.stringify(payload.status),
91+
// @ts-ignore
92+
JSON.stringify(payload[Object.keys(payload)[0]]?.status),
8593
payload,
8694
'sourceTab: ',
8795
sourceTab,
@@ -109,7 +117,10 @@ function MainContainer(): JSX.Element {
109117
break;
110118
}
111119
case 'changeTab': {
112-
console.log('MainContainer changeTab payload: ', payload);
120+
console.log(
121+
'MainContainer is dispatching this payload to the mainSlice setTab reducer: ',
122+
payload,
123+
);
113124
dispatch(setTab(payload));
114125
break;
115126
}
@@ -139,11 +150,11 @@ function MainContainer(): JSX.Element {
139150
const currentPort = chrome.runtime.connect({ name: 'uiPort1' });
140151

141152
// JR: why are we removing the listener just to readd it? logging here
142-
console.log('messageListener before removing: ', messageListener);
143-
console.log(
144-
'currentPort hasListener? before removing: ',
145-
currentPort.onMessage.hasListener(messageListener),
146-
);
153+
// console.log('messageListener before removing: ', messageListener);
154+
// console.log(
155+
// 'currentPort hasListener? before removing: ',
156+
// currentPort.onMessage.hasListener(messageListener),
157+
// );
147158
// If messageListener exists on currentPort, remove it
148159
while (currentPort.onMessage.hasListener(messageListener))
149160
currentPort.onMessage.removeListener(messageListener);

src/app/slices/mainSlice.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ export const mainSlice = createSlice({
103103
tabs[currentTab] || {};
104104
const { payload } = action;
105105

106-
console.log('mainSlice initialConnect reducer fired, ', payload);
106+
console.log('mainSlice initialConnect reducer fired, ', payload),
107+
'time: ',
108+
new Date().toLocaleString();
107109
Object.keys(payload).forEach((tab) => {
108110
// check if tab exists in memory
109111
// add new tab
@@ -136,15 +138,33 @@ export const mainSlice = createSlice({
136138
setTab: (state, action) => {
137139
const { tabs, currentTab } = state;
138140
const { mode } = tabs[currentTab] || {};
139-
console.log('mainSlice setTab, mode: ', JSON.stringify(mode), 'payload: ', action.payload);
141+
// console.log(
142+
// 'mode test. mode exists? ',
143+
// !!mode,
144+
// 'optional chained mode return value: ',
145+
// mode?.paused,
146+
// );
147+
console.log(
148+
'mainSlice setTab reducer received a payload. mode: ',
149+
JSON.stringify(mode),
150+
'payload: ',
151+
action.payload,
152+
);
140153
if (!mode?.paused) {
141154
if (typeof action.payload === 'number') {
142155
state.currentTab = action.payload;
143156
return;
144157
} else if (typeof action.payload === 'object') {
145158
state.currentTab = action.payload.tabId;
146159
if (action.payload?.title) state.currentTitle = action.payload.title;
147-
console.log('mainSlice setTab successful! currentTitle: ', state.currentTitle);
160+
console.log(
161+
'mainSlice setTab successful! state.currentTab: ',
162+
state.currentTab,
163+
'state.currentTitle: ',
164+
state.currentTitle,
165+
'state.tabs[currentTab].status: ',
166+
JSON.stringify(state.tabs[currentTab]?.status),
167+
);
148168
return;
149169
}
150170
}

src/extension/background.js

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,23 @@ chrome.runtime.onConnect.addListener((port) => {
162162
163163
Again, this port object is used for communication within your extension, not for communication with external ports or tabs in the Chrome browser. If you need to interact with specific tabs or external ports, you would use other APIs or methods, such as chrome.tabs or other Chrome Extension APIs.
164164
*/
165-
console.log('tabsObj onConnect: ', JSON.stringify(tabsObj));
165+
console.log(
166+
'tabsObj onConnect: ',
167+
JSON.stringify(tabsObj[0]?.status),
168+
'time: ',
169+
new Date().toLocaleString(),
170+
);
166171
portsArr.push(port); // push each Reactime communication channel object to the portsArr
167172
console.log('portsArr onConnect: ', Object.keys(portsArr));
168173

169-
// JR: CONSIDER DELETING
174+
// JR: CONSIDER DELETING?
170175
// 12.20.23 commenting out, possible culprit of many in no target bug
171176
if (portsArr.length > 0) {
172177
portsArr.forEach((bg, index) => {
173-
console.log('background onConnect. Send changeTab for port ', index);
178+
console.log(
179+
'background onConnect is sending a changeTab message to frontend for port ',
180+
index,
181+
);
174182
// go through each port object (each Reactime instance)
175183
bg.postMessage({
176184
// send passed in action object as a message to the current port
@@ -180,12 +188,16 @@ chrome.runtime.onConnect.addListener((port) => {
180188
});
181189
}
182190

183-
// JR: CONSIDER DELETING
191+
// JR: CONSIDER DELETING?
184192
if (Object.keys(tabsObj).length > 0) {
185-
port.postMessage({
186-
action: 'initialConnectSnapshots',
187-
payload: tabsObj,
188-
});
193+
console.log(
194+
'background onConnect is sending a initialConnectSnapshots message to frontend. Time: ',
195+
new Date().toLocaleString(),
196+
),
197+
port.postMessage({
198+
action: 'initialConnectSnapshots',
199+
payload: tabsObj,
200+
});
189201
}
190202

191203
// every time devtool is closed, remove the port from portsArr
@@ -277,7 +289,16 @@ chrome.runtime.onConnect.addListener((port) => {
277289
// INCOMING MESSAGE FROM CONTENT SCRIPT TO BACKGROUND.JS
278290
// background.js listening for a message from contentScript.js
279291
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
280-
console.log('background.js received message with action: ', request.action, request);
292+
console.log(
293+
'background.js received message from content script with type: ',
294+
request.type,
295+
'action: ',
296+
request.action,
297+
'request body: ',
298+
request,
299+
'time: ',
300+
new Date().toLocaleString(),
301+
);
281302
// AUTOMATIC MESSAGE SENT BY CHROME WHEN CONTENT SCRIPT IS FIRST LOADED: set Content
282303
if (request.type === 'SIGN_CONNECT') {
283304
return true;
@@ -307,7 +328,13 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
307328
// everytime we get a new tabId, add it to the object
308329
if (isReactTimeTravel && !(tabId in tabsObj)) {
309330
tabsObj[tabId] = createTabObj(tabTitle);
310-
console.log('tabsObj after createTabObj function call: ', tabsObj);
331+
332+
console.log(
333+
'tabsObj after createTabObj function call: ',
334+
JSON.stringify(tabsObj[0]?.status),
335+
'time: ',
336+
new Date().toLocaleString(),
337+
);
311338
}
312339

313340
switch (action) {
@@ -375,6 +402,11 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
375402
function: injectScript,
376403
args: [chrome.runtime.getURL('bundles/backend.bundle.js'), tabId],
377404
});
405+
406+
console.log(
407+
'background injected the backend bundle into the webpage. Time: ',
408+
new Date().toLocaleString(),
409+
);
378410
break;
379411
}
380412
case 'recordSnap': {
@@ -486,9 +518,11 @@ chrome.tabs.onActivated.addListener((info) => {
486518
// never set a reactime instance to the active tab
487519
if (!tab.pendingUrl?.match('^chrome-extension')) {
488520
activeTab = tab;
489-
console.log('tabs.onActivated info: ', info);
490-
console.log('activeTab: ', activeTab);
491-
console.log('tabs.onActivated portsArr: ', portsArr);
521+
console.log('background tabs.onActivated has fired. activeTab: ', JSON.stringify(activeTab));
522+
console.log(
523+
'background tabs.onActivated will send changeTab message to frontend if portsArr is > 0: ',
524+
Object.keys(portsArr),
525+
);
492526
if (portsArr.length > 0) {
493527
portsArr.forEach((bg) =>
494528
bg.postMessage({

0 commit comments

Comments
 (0)