Skip to content

Commit 8cc572f

Browse files
Commented out the console logs in the content and background scripts
1 parent bf03786 commit 8cc572f

File tree

2 files changed

+53
-53
lines changed

2 files changed

+53
-53
lines changed

extension/background.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let contentMessageQueue: any = [];
99

1010
// Listen for connection from content.ts and devtools panel
1111
chrome.runtime.onConnect.addListener(port => {
12-
console.log('BACKGROUND.TS: Connection established: ', port);
12+
// console.log('BACKGROUND.TS: Connection established: ', port);
1313
if (port.name === 'content-background') {
1414
handleContentConnection(port);
1515
} else if (port.name === 'background-devtool') {
@@ -40,25 +40,25 @@ function handleContentConnection(port: chrome.runtime.Port) {
4040
activeContentPort.onMessage.addListener(message => {
4141
// The background script goes inactive after 30 seconds idle so we log every 25 seconds
4242
if (message.type === 'heartbeat') {
43-
console.log('BACKGROUND.TS: Logging to keep service worker connected');
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
@@ -70,20 +70,20 @@ function handleDevToolsConnection(port: chrome.runtime.Port) {
7070
// If content.ts is connected send messages otherwise place in queue
7171
devToolPort.onMessage.addListener(message => {
7272
if (message.type === 'profiling-status') {
73-
console.log('BACKGROUND.TS: Profiling status', message);
73+
// console.log('BACKGROUND.TS: Profiling status', message);
7474
}
75-
console.log('Injecting content.js into tab with message: ', message);
75+
// console.log('Injecting content.js into tab with message: ', message);
7676
if (message.action === 'injectContentScript' && message.tabId) {
77-
console.log(
78-
'BACKGROUND.TS: Injecting content script into tab:',
79-
message.tabId
80-
);
77+
// console.log(
78+
// 'BACKGROUND.TS: Injecting content script into tab:',
79+
// message.tabId
80+
// );
8181
chrome.scripting.executeScript({
8282
target: { tabId: message.tabId },
8383
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)