You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if(!sourceTab&&action!=='keepAlive'){// if the sourceTab doesn't exist or is 0 and it is not a 'keepAlive' action
107
+
consttabsArray: Array<string>=Object.keys(payload);// we create a tabsArray of strings composed of keys from our payload object
108
+
constnumTabsArray: number[]=tabsArray.map((tab)=>Number(tab));// we then map out our tabsArray where we convert each string into a number
109
+
110
+
maxTab=Math.max(...numTabsArray);// we then get the largest tab number value
111
+
}
112
+
113
+
switch(action){
114
+
case'deleteTab': {
115
+
dispatch(deleteTab(payload));
116
+
break;
117
+
}
118
+
case'devTools': {
119
+
dispatch(noDev(payload));
120
+
break;
121
+
}
122
+
case'changeTab': {
123
+
console.log('received changeTab message')
124
+
dispatch(setTab(payload));
125
+
break;
126
+
}
127
+
case'sendSnapshots': {
128
+
dispatch(setTab(sourceTab));
129
+
// set state with the information received from the background script
130
+
dispatch(addNewSnapshots(payload));
131
+
break;
132
+
}
133
+
case'initialConnectSnapshots': {
134
+
dispatch(initialConnect(payload));
135
+
break;
136
+
}
137
+
case'setCurrentLocation': {
138
+
dispatch(setCurrentLocation(payload));
139
+
break;
140
+
}
141
+
default:
142
+
}
143
+
}
144
+
58
145
useEffect(()=>{
59
-
if(port)return;// only open port once so if it exists, do not run useEffect again
146
+
if(!connectRequested)return;// only open port once so if it exists, do not run useEffect again
60
147
61
148
// chrome.runtime allows our application to retrieve our service worker (our eventual bundles/background.bundle.js after running npm run build), details about the manifest, and allows us to listen and respond to events in our application lifecycle.
62
-
constcurrentPort=chrome.runtime.connect();// we connect to our service worker
63
-
64
-
// listen for a message containing snapshots from the /extension/build/background.js service worker
65
-
currentPort.onMessage.addListener(
66
-
// parameter message is an object with following type script properties
67
-
(message: {
68
-
action: string;
69
-
payload: Record<string,unknown>;
70
-
sourceTab: number
71
-
})=>{
72
-
const{ action, payload, sourceTab }=message;
73
-
letmaxTab: number;
74
-
75
-
if(!sourceTab&&action!=='keepAlive'){// if the sourceTab doesn't exist or is 0 and it is not a 'keepAlive' action
76
-
consttabsArray: Array<string>=Object.keys(payload);// we create a tabsArray of strings composed of keys from our payload object
77
-
constnumTabsArray: number[]=tabsArray.map((tab)=>Number(tab));// we then map out our tabsArray where we convert each string into a number
78
-
79
-
maxTab=Math.max(...numTabsArray);// we then get the largest tab number value
80
-
}
81
149
82
-
switch(action){
83
-
case'deleteTab': {
84
-
dispatch(deleteTab(payload));
85
-
break;
86
-
}
87
-
case'devTools': {
88
-
dispatch(noDev(payload));
89
-
break;
90
-
}
91
-
case'changeTab': {
92
-
dispatch(setTab(payload));
93
-
break;
94
-
}
95
-
case'sendSnapshots': {
96
-
dispatch(setTab(sourceTab));
97
-
// set state with the information received from the background script
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.
160
163
*/
164
+
165
+
console.log('Port: ',port);
166
+
portSuccessfullyConnected=port ? true : false;
161
167
162
168
portsArr.push(port);// push each Reactime communication channel object to the portsArr
163
-
164
-
// On Reactime launch: make sure RT's active tab is correct
165
-
if(portsArr.length>0){
166
-
portsArr.forEach((bg)=>{// go through each port object (each Reactime instance)
167
-
bg.postMessage({// send passed in action object as a message to the current port
0 commit comments