Skip to content

Commit 6a893c4

Browse files
committed
cleaned up some comments and deleted old error fixing attempts in the contextclick listener in background.js
1 parent 6cae13b commit 6a893c4

File tree

1 file changed

+6
-42
lines changed

1 file changed

+6
-42
lines changed

src/extension/background.js

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
279279
let isReactTimeTravel = false;
280280

281281
if (name) {
282-
//console.log(value);
283282
metrics[name] = value;
284283
}
285284

@@ -500,17 +499,16 @@ chrome.runtime.onInstalled.addListener(() => {
500499
// JR 12.19.23
501500
// As of V22, if multiple monitors are used, it would open the reactime panel on the other screen, which was inconvenient when opening repeatedly for debugging.
502501
// V23 fixes this by making use of chrome.windows.getCurrent to get the top and left of the screen which invoked the extension.
503-
// The reason you must use chrome.windows.getCurrent is that as of chrome manifest V3, background.js is a 'service worker', which does not have access to the DOM or to the native 'window' method.
504-
// chrome.windows.getCurrent allows us to still get the window from within a service worker. It returns a promise (asynchronous), so all resulting functionality must happen in the callback function,
505-
// or it will run before 'invokedScreen' variables have been captured.
502+
// As of chrome manifest V3, background.js is a 'service worker', which does not have access to the DOM or to the native 'window' method, so we use chrome.windows.getCurrent(callback)
503+
// chrome.windows.getCurrent returns a promise (asynchronous), so all resulting functionality must happen in the callback function, or it will run before 'invokedScreen' variables have been captured.
506504
chrome.contextMenus.onClicked.addListener(({ menuItemId }) => {
505+
507506
// // this was a test to see if I could dynamically set the left property to be the 0 origin of the invoked DISPLAY (as opposed to invoked window).
508507
// // this would allow you to split your screen, keep the browser open on the right side, and reactime always opens at the top left corner.
509-
// // unfortunately it does not tell you which display is the one that invoked it, just the array of all available displays. Leaving for future iterators
508+
// // however it does not tell you which display is the one that invoked it, just gives the array of all available displays. Depending on your monitor setup, it may differ. Leaving for future iterators
510509
// chrome.system.display.getInfo((displayUnitInfo) => {
511510
// console.log(displayUnitInfo);
512511
// });
513-
514512
chrome.windows.getCurrent((window) => {
515513
const invokedScreenTop = 75; // window.top || 0;
516514
const invokedScreenLeft = window.left || 0;
@@ -527,49 +525,15 @@ chrome.contextMenus.onClicked.addListener(({ menuItemId }) => {
527525
if (menuItemId === 'reactime') chrome.windows.create(options);
528526
});
529527

530-
//JR 12.20.23
531-
//JR 1.8.23: this code fixes the no target error (still gets stuck on reactdevtools installed check), but creates an error where the addNewSnapshots reducer has an error.
528+
// JR 1.9.23: this code fixes the no target error on load by triggering chrome tab reload before the panel spins up.
529+
// It does not solve the root issue, which was deeply researched during v23 but we ran out of time to solve. Please see the readme for more information.
532530
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
533531
console.log('onContext click tab info', tabs, new Date().toLocaleString());
534532
if (tabs.length) {
535533
const invokedTab = tabs[0];
536534
const invokedTabId = invokedTab.id;
537535
const invokedTabTitle = invokedTab.title;
538536
chrome.tabs.reload(invokedTabId)
539-
// tabsObj[invokedTabId] = createTabObj(invokedTabTitle);
540-
// console.log('onContextClick tabsObj created ', tabsObj);
541-
// activeTab = invokedTab;
542-
543-
// inject backend script
544-
// const injectScript = (file, tab) => {
545-
// const htmlBody = document.getElementsByTagName('body')[0];
546-
// const script = document.createElement('script');
547-
// script.setAttribute('id', 'reactime-backend-script');
548-
// script.setAttribute('type', 'text/javascript');
549-
// script.setAttribute('src', file);
550-
// // eslint-disable-next-line prefer-template
551-
// htmlBody.appendChild(script);
552-
// };
553-
554-
// console.log('background is injecting the backend script', new Date().toLocaleString());
555-
// chrome.scripting.executeScript({
556-
// target: { tabId: invokedTabId },
557-
// func: injectScript,
558-
// args: [chrome.runtime.getURL('bundles/backend.bundle.js'), invokedTabId],
559-
// });
560-
561-
// console.log('contextclick invokedTab url, ', invokedTab.url, 'portsArr: ', portsArr);
562-
// if (!invokedTab.url?.match('^chrome-extension')) {
563-
// if (portsArr.length > 0) {
564-
// portsArr.forEach((bg) => {
565-
// console.log('contextClick is sending change Tab message to ', bg);
566-
// bg.postMessage({
567-
// action: 'changeTab',
568-
// payload: { tabId: invokedTabId, title: invokedTabTitle },
569-
// });
570-
// });
571-
// }
572-
// }
573537
}
574538
});
575539
});

0 commit comments

Comments
 (0)