Skip to content

Commit 4ac64c3

Browse files
authored
fix: statically inject courier content script (#238)
1 parent 592f5eb commit 4ac64c3

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

workspace/extension/src/client/core.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { send } from './runtime.js';
33
import { index as v4 } from './svelte-4.js';
44
import { serialize } from './utils.js';
55

6-
// @ts-ignore - for the app to call with `eval`
6+
// @ts-ignore - https://developer.chrome.com/docs/extensions/how-to/devtools/extend-devtools#selected-element
77
window['#SvelteDevTools'] = {
88
/**
99
* @param {string} id

workspace/extension/static/background.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ function courier(tabId, changed) {
5656

5757
chrome.scripting.executeScript({
5858
target: { tabId },
59+
60+
// ensures we're listening to the events before they're dispatched
5961
injectImmediately: true,
6062

6163
// no lexical context, `func` is serialized and deserialized.
@@ -69,15 +71,6 @@ function courier(tabId, changed) {
6971
// - chrome.i18n
7072
// - chrome.runtime
7173
func: () => {
72-
const source = chrome.runtime.getURL('/courier.js');
73-
if (document.querySelector(`script[src="${source}"]`)) return;
74-
75-
// attach script manually instead of declaring through `files`
76-
// because `detail` in the dispatched custom events is `null`
77-
const script = document.createElement('script');
78-
script.setAttribute('src', source);
79-
document.head.appendChild(script);
80-
8174
chrome.runtime.onMessage.addListener((message, sender) => {
8275
if (sender.id !== chrome.runtime.id) return; // unexpected sender
8376
window.postMessage(message); // relay to content script (courier.js)

workspace/extension/static/manifest.json

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424
"scripts": ["background.js"],
2525
"service_worker": "background.js"
2626
},
27+
"content_scripts": [
28+
{
29+
"matches": ["<all_urls>"],
30+
"js": ["courier.js"],
31+
"run_at": "document_start",
32+
"world": "MAIN"
33+
}
34+
],
2735
"devtools_page": "register.html",
2836
"host_permissions": ["*://*/*"],
2937
"permissions": ["activeTab", "scripting"],

0 commit comments

Comments
 (0)