Skip to content

Commit 2564ef4

Browse files
committed
Committing work in progress changes. Currently investigating content script security.
1 parent 61bd748 commit 2564ef4

File tree

3 files changed

+48
-30
lines changed

3 files changed

+48
-30
lines changed

src/extension/background.js

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,12 @@ chrome.runtime.onConnect.addListener(port => {
199199
return true;
200200
case 'launchContentScript':
201201
// !!! in Manifest Version 3 this will need to be changed to the commented out code below !!!
202-
// chrome.scripting.executeScript({
203-
// target: { tabId },
204-
// files: ['bundles/content.bundle.js'],
205-
// });
202+
chrome.scripting.executeScript({
203+
target: { tabId },
204+
files: ['bundles/content.bundle.js'],
205+
});
206206
// This line below will need to be removed
207-
chrome.tabs.executeScript(tabId, { file: 'bundles/content.bundle.js' });
207+
// chrome.tabs.executeScript(tabId, { file: 'bundles/content.bundle.js' });
208208
return true;
209209
case 'jumpToSnap':
210210
chrome.tabs.sendMessage(tabId, msg);
@@ -282,20 +282,34 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
282282
// This injects a script into the app that you're testing Reactime on,
283283
// so that Reactime's backend files can communicate with the app's DOM.
284284
case 'injectScript': {
285-
chrome.tabs.executeScript(tabId, {
286-
code: `
287-
// Function will attach script to the dom
288-
const injectScript = (file, tag) => {
289-
const htmlBody = document.getElementsByTagName(tag)[0];
290-
const script = document.createElement('script');
291-
script.setAttribute('type', 'text/javascript');
292-
script.setAttribute('src', file);
293-
document.title=${tabId} + '-' + document.title
294-
htmlBody.appendChild(script);
295-
};
296-
injectScript(chrome.runtime.getURL('bundles/backend.bundle.js'), 'body');
297-
`,
285+
chrome.scripting.executeScript({
286+
target: { tabId },
287+
func: () => {
288+
const injectScript = (file, tag) => {
289+
const htmlBody = document.getElementsByTagName(tag)[0];
290+
const script = document.createElement('script');
291+
script.setAttribute('type', 'text/javascript');
292+
script.setAttribute('src', file);
293+
document.title = tabId + '-' + document.title;
294+
htmlBody.appendChild(script);
295+
};
296+
injectScript(chrome.runtime.getURL('bundles/backend.bundle.js'), 'body');
297+
},
298298
});
299+
// chrome.tabs.executeScript(tabId, {
300+
// code: `
301+
// // Function will attach script to the dom
302+
// const injectScript = (file, tag) => {
303+
// const htmlBody = document.getElementsByTagName(tag)[0];
304+
// const script = document.createElement('script');
305+
// script.setAttribute('type', 'text/javascript');
306+
// script.setAttribute('src', file);
307+
// document.title=${tabId} + '-' + document.title
308+
// htmlBody.appendChild(script);
309+
// };
310+
// injectScript(chrome.runtime.getURL('bundles/backend.bundle.js'), 'body');
311+
// `,
312+
// });
299313
break;
300314
}
301315
case 'recordSnap': {

src/extension/build/manifest.json

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
"version": "13.0.0",
44
"devtools_page": "devtools.html",
55
"description": "A Chrome extension that helps debug React applications by memorizing the state of components with every render.",
6-
"manifest_version": 2,
7-
"content_security_policy": "script-src 'self' https://www.gstatic.com:* 'unsafe-eval'; object-src 'self'",
6+
"manifest_version": 3,
7+
"content_security_policy": {
8+
"extension_pages": "script-src 'self'; object-src 'self'"
9+
},
810
"background": {
9-
"scripts": [
10-
"bundles/background.bundle.js",
11-
"bundles/content.bundle.js"
12-
],
13-
"persistent": false
11+
"service-worker": "bundles/background.bundle.js"
1412
},
1513
"icons": {
1614
"48": "assets/icon48.png",
@@ -27,13 +25,19 @@
2725
]
2826
}
2927
],
30-
"web_accessible_resources": [
31-
"bundles/backend.bundle.js"
32-
],
28+
"web_accessible_resources": [{
29+
"resources": ["bundles/backend.bundle.js"],
30+
"matches": [
31+
"http://localhost/*",
32+
"https://localhost/*"
33+
]
34+
}],
3335
"permissions": [
3436
"contextMenus",
3537
"tabs",
36-
"activeTab",
38+
"activeTab"
39+
],
40+
"host_permissions": [
3741
"http://localhost/*",
3842
"https://localhost/*",
3943
"<all_urls>"

src/extension/build/panel.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
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>
13+
<!-- <script type="text/javascript" src="https://www.gstatic.com/charts/49/loader.js"></script> -->
1414
</body>
1515
</html>

0 commit comments

Comments
 (0)