Skip to content

Commit 03281a0

Browse files
authored
Merge pull request #56 from oslabs-beta/austin/remove-console-logs
Austin/remove console logs
2 parents a4ed265 + d1300d9 commit 03281a0

File tree

18 files changed

+204
-187
lines changed

18 files changed

+204
-187
lines changed

extension/background.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
console.log("BACKGROUND.TS: Loaded");
1+
// console.log("BACKGROUND.TS: Loaded");
22

33
let devToolPort: chrome.runtime.Port | null = null;
44
let activeContentPort: chrome.runtime.Port | null = null;
@@ -8,11 +8,11 @@ let devToolMessageQueue: any = [];
88
let contentMessageQueue: any = [];
99

1010
// Listen for connection from content.ts and devtools panel
11-
chrome.runtime.onConnect.addListener((port) => {
12-
console.log("BACKGROUND.TS: Connection established: ", port);
13-
if (port.name === "content-background") {
11+
chrome.runtime.onConnect.addListener(port => {
12+
// console.log('BACKGROUND.TS: Connection established: ', port);
13+
if (port.name === 'content-background') {
1414
handleContentConnection(port);
15-
} else if (port.name === "background-devtool") {
15+
} else if (port.name === 'background-devtool') {
1616
handleDevToolsConnection(port);
1717
}
1818
});
@@ -37,28 +37,28 @@ function handleContentConnection(port: chrome.runtime.Port) {
3737
contentMessageQueue = [];
3838

3939
// If devtool is connected send messages otherwise place in queue
40-
activeContentPort.onMessage.addListener((message) => {
40+
activeContentPort.onMessage.addListener(message => {
4141
// The background script goes inactive after 30 seconds idle so we log every 25 seconds
42-
if (message.type === "heartbeat") {
43-
console.log("BACKGROUND.TS: Logging to keep service worker connected");
42+
if (message.type === 'heartbeat') {
43+
// console.log('BACKGROUND.TS: Logging to keep service worker connected');
4444
}
4545

4646
if (devToolPort) {
47-
console.log("BACKGROUND.TS: Message to dev tool", message);
47+
// console.log('BACKGROUND.TS: Message to dev tool', message);
4848
devToolPort.postMessage(message);
4949
} else {
5050
devToolMessageQueue.push(message);
5151
}
5252
});
5353

5454
port.onDisconnect.addListener(() => {
55-
console.log("BACKGROUND.TS: Content.ts disconnected");
55+
// console.log('BACKGROUND.TS: Content.ts disconnected');
5656
activeContentPort = null;
5757
});
5858
}
5959

6060
function handleDevToolsConnection(port: chrome.runtime.Port) {
61-
console.log("BACKGROUND.TS: DevTool connected");
61+
// console.log('BACKGROUND.TS: DevTool connected');
6262
devToolPort = port;
6363

6464
// Send queued messages from the devtool before connection was established
@@ -68,22 +68,22 @@ function handleDevToolsConnection(port: chrome.runtime.Port) {
6868
devToolMessageQueue = [];
6969

7070
// If content.ts is connected send messages otherwise place in queue
71-
devToolPort.onMessage.addListener((message) => {
72-
if (message.type === "profiling-status") {
73-
console.log("BACKGROUND.TS: Profiling status", message);
71+
devToolPort.onMessage.addListener(message => {
72+
if (message.type === 'profiling-status') {
73+
// console.log('BACKGROUND.TS: Profiling status', message);
7474
}
75-
console.log('Injecting content.js into tab with message: ', message);
76-
if (message.action === "injectContentScript" && message.tabId) {
77-
console.log(
78-
"BACKGROUND.TS: Injecting content script into tab:",
79-
message.tabId
80-
);
75+
// console.log('Injecting content.js into tab with message: ', message);
76+
if (message.action === 'injectContentScript' && message.tabId) {
77+
// console.log(
78+
// 'BACKGROUND.TS: Injecting content script into tab:',
79+
// message.tabId
80+
// );
8181
chrome.scripting.executeScript({
8282
target: { tabId: message.tabId },
83-
files: ["content.js"],
83+
files: ['content.js'],
8484
});
8585
} else if (activeContentPort) {
86-
console.log("BACKGROUND.TS: Message to content.ts", message);
86+
// console.log('BACKGROUND.TS: Message to content.ts', message);
8787
activeContentPort.postMessage(message);
8888
} else {
8989
// console.log('BACKGROUND.TS: Message added to content.ts queue');
@@ -92,7 +92,7 @@ function handleDevToolsConnection(port: chrome.runtime.Port) {
9292
});
9393

9494
port.onDisconnect.addListener(() => {
95-
console.log("BACKGROUND.TS: DevTool disconnected");
95+
// console.log('BACKGROUND.TS: DevTool disconnected');
9696
devToolPort = null;
9797
});
9898
}

extension/content_scripts/content.ts

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
// Function to inject the script into the current tab
2-
const inject = () => {
3-
let isInjected = false;
4-
5-
return function(fileName: string) {
6-
if (!isInjected) {
7-
if (document.getElementById("treeScript-jkhsdfkdshdsf")) {
8-
console.log('Tree script already injected');
9-
return;
10-
}
11-
const treeScript = document.createElement("script");
12-
// Adding a unique id to the script tag to prevent it from being injected multiple times because my closure isn't working for some reason (not sure if it's because of how content scripts work or something else)
13-
treeScript.id = "treeScript-jkhsdfkdshdsf";
14-
treeScript.setAttribute("type", "text/javascript");
15-
treeScript.setAttribute("src", chrome.runtime.getURL(fileName));
16-
document.body.appendChild(treeScript);
17-
isInjected = true;
18-
console.log('Injected tree script');
19-
} else {
20-
console.log('Tree script already injected');
1+
// Function to inject the script into the current tab
2+
const inject = () => {
3+
let isInjected = false;
4+
5+
return function (fileName: string) {
6+
if (!isInjected) {
7+
if (document.getElementById('treeScript-jkhsdfkdshdsf')) {
8+
// console.log('Tree script already injected');
9+
return;
2110
}
11+
const treeScript = document.createElement('script');
12+
// Adding a unique id to the script tag to prevent it from being injected multiple times because my closure isn't working for some reason (not sure if it's because of how content scripts work or something else)
13+
treeScript.id = 'treeScript-jkhsdfkdshdsf';
14+
treeScript.setAttribute('type', 'text/javascript');
15+
treeScript.setAttribute('src', chrome.runtime.getURL(fileName));
16+
document.body.appendChild(treeScript);
17+
isInjected = true;
18+
// console.log('Injected tree script');
19+
} else {
20+
// console.log('Tree script already injected');
2221
}
2322
};
23+
};
2424

2525
// Immediatly-Invoked Function Expression (IIFE)
2626
(function () {
2727
// Check if the content script has already been loaded into the current tab
2828
// Prevents it from injecting into the same page twice if the developer opens and closes the dev tool
2929
if (window.myContentScriptLoaded) {
30-
console.log("CONTENT.TS: Content script already injected");
30+
// console.log("CONTENT.TS: Content script already injected");
3131
return;
3232
} else {
3333
// Set the flag on the window to indicate the content script has already been loaded in the tab
3434
window.myContentScriptLoaded = true;
35-
console.log("CONTENT.TS: Loaded");
35+
// console.log("CONTENT.TS: Loaded");
3636
}
3737

3838
let appConnected = false;
@@ -44,21 +44,21 @@
4444

4545
// Function to setup and initialize the background port
4646
function setupPort() {
47-
console.log("CONTENT.TS: Background.ts Connected");
47+
// console.log("CONTENT.TS: Background.ts Connected");
4848

4949
// Connect to background script
50-
backgroundPort = chrome.runtime.connect({ name: "content-background" });
50+
backgroundPort = chrome.runtime.connect({ name: 'content-background' });
5151

5252
// Handle background.ts messages - send message if connected to app otherwise add to queue
53-
backgroundPort.onMessage.addListener((message) => {
54-
console.log("CONTENT.TS: BackgroundPort.OnMessage: ", message.data?.type);
53+
backgroundPort.onMessage.addListener(message => {
54+
// console.log("CONTENT.TS: BackgroundPort.OnMessage: ", message.data?.type);
5555
if (appConnected) {
56-
console.log("CONTENT.TS: Message to app", message);
56+
// console.log("CONTENT.TS: Message to app", message);
5757
// Inject script to get react tree data
58-
if (message.type === "profiling-status") {
59-
console.log('tree script *should* be injected');
58+
if (message.type === 'profiling-status') {
59+
// console.log('tree script *should* be injected');
6060
const scriptToInject = inject();
61-
scriptToInject("inject.js");
61+
scriptToInject('inject.js');
6262
// return so message isn't posted anywhere
6363
return;
6464
}
@@ -69,7 +69,7 @@
6969
});
7070

7171
backgroundPort.onDisconnect.addListener(() => {
72-
console.log("CONTENT.TS: Background.ts Disconnected");
72+
// console.log('CONTENT.TS: Background.ts Disconnected');
7373
// Reset the port to trigger reconnection attempt
7474
backgroundPort = null;
7575
setupPort();
@@ -82,22 +82,22 @@
8282
}
8383

8484
// Add listener to the window to handle messages from the app
85-
window.addEventListener("message", handleMessageFromApp, false);
85+
window.addEventListener('message', handleMessageFromApp, false);
8686

8787
function handleMessageFromApp(message: MessageEvent) {
88-
console.log("CONTENT.TS: handleMessageFromApp", message.data?.type);
88+
// console.log('CONTENT.TS: handleMessageFromApp', message.data?.type);
8989
// Initial message from the app to confirm connection
90-
if (message.data?.type === "app-connected") {
91-
console.log("CONTENT.TS: App Connected");
90+
if (message.data?.type === 'app-connected') {
91+
// console.log('CONTENT.TS: App Connected');
9292
clearInterval(appConnectionInterval);
9393
appConnected = true;
9494
appMessageQueue.forEach((message: any) => window.postMessage(message));
9595
appMessageQueue = [];
9696
}
9797

9898
// Send tree data to background.ts
99-
if (message.data.type && message.data.type === "tree") {
100-
console.log("CONTENT.ts: component tree sending event: ", message);
99+
if (message.data.type && message.data.type === 'tree') {
100+
// console.log('CONTENT.ts: component tree sending event: ', message);
101101
backgroundPort?.postMessage({
102102
type: message.data.type,
103103
data: JSON.parse(message.data.eventListStr),
@@ -106,7 +106,7 @@
106106
}
107107

108108
// All other messages are sent to background.ts
109-
if (message.data?.type === "event") {
109+
if (message.data?.type === 'event') {
110110
// console.log('CONTENT.TS: Message from App:', message);
111111
sendMessageToBackground(message);
112112
}
@@ -115,7 +115,7 @@
115115
// Notify app that content.ts is ready
116116
function establishAppConnection() {
117117
if (!appConnected) {
118-
window.postMessage({ type: "content-script-ready" }, "*");
118+
window.postMessage({ type: 'content-script-ready' }, '*');
119119
}
120120
}
121121

@@ -125,7 +125,7 @@
125125

126126
// Function to send a heartbeat message to the background script to keep it active
127127
function sendHeartbeat() {
128-
backgroundPort?.postMessage({ type: "heartbeat" });
128+
backgroundPort?.postMessage({ type: 'heartbeat' });
129129
// console.log('heartbeat');
130130
}
131131

0 commit comments

Comments
 (0)