Skip to content

Commit a8cb004

Browse files
committed
Committing a working version of Reactime using a V3 manifest. Current solution does not work in dev mode.
1 parent 7dc7895 commit a8cb004

File tree

3 files changed

+25
-56
lines changed

3 files changed

+25
-56
lines changed

src/extension/background.js

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Import snapshots from "../app/components/snapshots".
2-
import 'core-js';
2+
// import 'core-js';
33

4-
console.log('Hello from line 4');
54
// Store ports in an array.
65
const portsArr = [];
76
const reloaded = {};
@@ -288,35 +287,22 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
288287
// so that Reactime's backend files can communicate with the app's DOM.
289288
case 'injectScript': {
290289
console.log('Hello from line 287');
290+
291+
const injectScript = (file, tabId) => {
292+
const htmlBody = document.getElementsByTagName('body')[0];
293+
const script = document.createElement('script');
294+
script.setAttribute('type', 'text/javascript');
295+
script.setAttribute('src', file);
296+
// eslint-disable-next-line prefer-template
297+
document.title = tabId + '-' + document.title;
298+
htmlBody.appendChild(script);
299+
};
300+
291301
chrome.scripting.executeScript({
292302
target: { tabId },
293-
func: tab => {
294-
const injectScript = (file, tag) => {
295-
const htmlBody = document.getElementsByTagName(tag)[0];
296-
const script = document.createElement('script');
297-
script.setAttribute('type', 'text/javascript');
298-
script.setAttribute('src', file);
299-
document.title = tab + '-' + document.title;
300-
htmlBody.appendChild(script);
301-
};
302-
injectScript(chrome.runtime.getURL('bundles/backend.bundle.js'), 'body');
303-
},
304-
args: [tabId],
303+
function: injectScript,
304+
args: [chrome.runtime.getURL('bundles/backend.bundle.js'), tabId],
305305
});
306-
// chrome.tabs.executeScript(tabId, {
307-
// code: `
308-
// // Function will attach script to the dom
309-
// const injectScript = (file, tag) => {
310-
// const htmlBody = document.getElementsByTagName(tag)[0];
311-
// const script = document.createElement('script');
312-
// script.setAttribute('type', 'text/javascript');
313-
// script.setAttribute('src', file);
314-
// document.title=${tabId} + '-' + document.title
315-
// htmlBody.appendChild(script);
316-
// };
317-
// injectScript(chrome.runtime.getURL('bundles/backend.bundle.js'), 'body');
318-
// `,
319-
// });
320306
break;
321307
}
322308
case 'recordSnap': {
@@ -442,6 +428,7 @@ chrome.runtime.onInstalled.addListener(() => {
442428
title: 'Reactime',
443429
contexts: ['page', 'selection', 'image', 'link'],
444430
});
431+
console.log('Context Menu Created');
445432
});
446433

447434
// when context menu is clicked, listen for the menuItemId,

src/extension/build/manifest.json

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,25 @@
44
"devtools_page": "devtools.html",
55
"description": "A Chrome extension that helps debug React applications by memorizing the state of components with every render.",
66
"manifest_version": 3,
7-
"content_security_policy": {
8-
"extension_pages": "script-src 'self'; object-src 'self'"
9-
},
107
"background": {
11-
"service-worker": "bundles/background.bundle.js"
8+
"service_worker": "bundles/background.bundle.js"
129
},
1310
"icons": {
1411
"48": "assets/icon48.png",
1512
"128": "assets/icon128.png"
1613
},
1714
"content_scripts": [
1815
{
19-
"matches": [
20-
"http://localhost/*",
21-
"https://localhost/*"
22-
],
23-
"js": [
24-
"bundles/content.bundle.js"
25-
]
16+
"matches": ["<all_urls>"],
17+
"js": ["bundles/content.bundle.js"]
2618
}
2719
],
28-
"web_accessible_resources": [{
29-
"resources": ["bundles/backend.bundle.js"],
30-
"matches": [
31-
"http://localhost/*",
32-
"https://localhost/*"
33-
]
34-
}],
35-
"permissions": [
36-
"contextMenus",
37-
"tabs",
38-
"activeTab"
20+
"web_accessible_resources": [
21+
{
22+
"resources": ["bundles/backend.bundle.js"],
23+
"matches": ["<all_urls>"]
24+
}
3925
],
40-
"host_permissions": [
41-
"http://localhost/*",
42-
"https://localhost/*",
43-
"<all_urls>"
44-
]
26+
"permissions": ["contextMenus", "tabs", "activeTab", "scripting"],
27+
"host_permissions": ["<all_urls>"]
4528
}

src/extension/build/panel.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@
1010
<body>
1111
<div id="root"></div>
1212
<script type="text/javascript" src="bundles/app.bundle.js"></script>
13-
<!-- <script type="text/javascript" src="https://www.gstatic.com/charts/49/loader.js"></script> -->
1413
</body>
1514
</html>

0 commit comments

Comments
 (0)