Skip to content

Commit 0436889

Browse files
authored
feat: add firefox support (#185)
1 parent aea036f commit 0436889

File tree

9 files changed

+29
-33
lines changed

9 files changed

+29
-33
lines changed

.github/workflows/release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ jobs:
1919

2020
- run: pnpm install
2121
- run: pnpm build
22-
- run: cd build && zip -r svelte-devtools-${{ github.sha }} *
22+
- run: cd build && zip -r svelte-devtools *
2323

2424
- uses: actions/upload-artifact@v3
2525
with:
2626
name: extension-${{ github.sha }}
27-
path: build/svelte-devtools-${{ github.sha }}.zip
27+
path: build/svelte-devtools.zip
2828

2929
# publish:
3030
# runs-on: ubuntu-latest

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
</picture>
88
</a>
99

10-
Svelte DevTools is a Chrome extension for the [Svelte](https://svelte.dev/) framework. It allows you to inspect the Svelte state and component hierarchies in the Developer Tools.
10+
Svelte DevTools is a browser extension for the [Svelte](https://svelte.dev/) framework. It allows you to inspect the Svelte state and component hierarchies in the Developer Tools.
1111

1212
After installing you will see a new tab in Developer Tools. This tab displays a tree of Svelte components, HTMLx blocks, and DOM elements that were rendered on the page. By selecting one of the nodes in the tree, you can inspect and edit its current state in the panel to the right.
1313

14+
> For Firefox users, you can grab the [`.zip` file of the latest version from the GitHub releases page](https://github.com/sveltejs/svelte-devtools/releases/latest) and load it as a temporary extension. Note that you may need to enable "Always Allow on localhost" in the extension settings.
15+
1416
![2.0.0 Screenshot](./.github/assets/screenshot-2.0.0.png '2.0.0 Screenshot')
1517

1618
## Requirements

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"dev": "pnpm run --parallel \"/dev:*/\"",
66
"dev:app": "vite build --watch",
77
"dev:scripts": "rollup -cw",
8-
"build": "vite build && rollup -c",
8+
"build": "rollup -c && vite build",
9+
"build:zip": "cd build && zip -r svelte-devtools.zip *",
10+
"build:tar": "cd build && tar -czf svelte-devtools.tar.gz *",
911
"format": "prettier -w .",
1012
"check": "pnpm run --parallel \"/check:*/\"",
1113
"check:style": "prettier -c .",

rollup.config.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ export default defineConfig([
77
file: 'build/background.js',
88
},
99
},
10-
{
11-
input: 'static/sensor.js',
12-
output: {
13-
file: 'build/sensor.js',
14-
},
15-
},
1610
{
1711
input: 'src/client/index.js',
1812
output: [

src/app.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ declare global {
5858
children: SvelteBlockDetail[];
5959
/** `type: 'element' | 'component'` */
6060
parent?: SvelteBlockDetail;
61-
/** like `parent` but `type: 'component'` */
61+
/** like `parent` but `type: 'component'` */
6262
container?: SvelteBlockDetail;
6363

6464
block: SvelteComponentDetail['component']['$$']['fragment'];

static/background.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,36 @@ function courier(tabId, changed) {
108108

109109
chrome.tabs.onActivated.addListener(({ tabId }) => sensor(tabId));
110110
chrome.tabs.onUpdated.addListener(
111-
(tabId, changed) => changed.status === 'unloaded' && sensor(tabId),
111+
(tabId, changed) => changed.status === 'complete' && sensor(tabId),
112112
);
113113

114114
/** @param {number} tabId */
115115
async function sensor(tabId) {
116116
try {
117+
// add SvelteDevTools event listener
117118
await chrome.scripting.executeScript({
118119
target: { tabId },
119-
120120
func: () => {
121-
const source = chrome.runtime.getURL('/sensor.js');
122-
document.querySelector(`script[src="${source}"]`)?.remove();
123-
const script = document.createElement('script');
124-
script.setAttribute('src', source);
125-
document.head.appendChild(script);
126-
127121
document.addEventListener('SvelteDevTools', ({ detail }) => {
128122
chrome.runtime.sendMessage(detail);
129123
});
130124
},
131125
});
126+
// capture data to send to listener
127+
await chrome.scripting.executeScript({
128+
target: { tabId },
129+
world: 'MAIN',
130+
func: () => {
131+
// @ts-ignore - injected if the website is using svelte
132+
const [major] = [...(window.__svelte?.v ?? [])];
133+
134+
document.dispatchEvent(
135+
new CustomEvent('SvelteDevTools', {
136+
detail: { type: 'bypass::ext/icon:set', payload: major },
137+
}),
138+
);
139+
},
140+
});
132141
} catch {
133142
// for internal URLs like `chrome://` or `edge://` and extension gallery
134143
// https://chromium.googlesource.com/chromium/src/+/ee77a52baa1f8a98d15f9749996f90e9d3200f2d/chrome/common/extensions/chrome_extensions_client.cc#131

static/manifest.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121
}
2222
},
2323
"background": {
24+
"scripts": ["background.js"],
2425
"service_worker": "background.js"
2526
},
2627
"devtools_page": "register.html",
2728
"host_permissions": ["*://*/*"],
2829
"permissions": ["activeTab", "scripting"],
29-
"web_accessible_resources": [
30-
{ "matches": ["*://*/*"], "resources": ["courier.js"] },
31-
{ "matches": ["*://*/*"], "resources": ["sensor.js"], "world": "MAIN" }
32-
]
30+
"web_accessible_resources": [{ "matches": ["*://*/*"], "resources": ["courier.js"] }]
3331
}

static/register.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!doctype html>
12
<html>
23
<body>
34
<script src="register.js"></script>

static/sensor.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)