Skip to content

Commit 555671f

Browse files
authored
feat(extension): add VitePress detector (#523)
1 parent 12614a9 commit 555671f

File tree

11 files changed

+104
-4
lines changed

11 files changed

+104
-4
lines changed
8.2 KB
Loading
572 Bytes
Loading
2.11 KB
Loading
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<meta charset="utf-8" />
2+
<link rel="stylesheet" type="text/css" href="./popup.css" />
3+
4+
<p>
5+
<strong>VitePress + Vue.js is detected on this page.</strong><br />
6+
Devtools inspection is not available because it's in production mode or
7+
explicitly disabled by the author.
8+
</p>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<meta charset="utf-8" />
2+
<link rel="stylesheet" type="text/css" href="./popup.css" />
3+
4+
<div class="flex">
5+
<div class="screenshot">
6+
<img src="./devtools-screenshot.png" alt="Screenshot" />
7+
</div>
8+
9+
<div>
10+
<p>
11+
<strong>VitePress + Vue.js is detected on this page.</strong><br />
12+
Open DevTools and look for the Vue panel.
13+
</p>
14+
15+
<p>
16+
<a
17+
href="https://devtools-next.vuejs.org/help/troubleshooting"
18+
target="_blank"
19+
>Troubleshooting</a
20+
>
21+
</p>
22+
</div>
23+
</div>

packages/chrome-extension/src/background.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ chrome.runtime.onConnect.addListener((port) => {
9090

9191
chrome.runtime.onMessage.addListener((req, sender) => {
9292
if (sender.tab && req.vueDetected) {
93-
const suffix = req.nuxtDetected ? '.nuxt' : ''
93+
let suffix = ''
94+
95+
if (req.nuxtDetected)
96+
suffix = '.nuxt'
97+
else if (req.vitePressDetected)
98+
suffix = '.vitepress'
9499

95100
chrome.action.setIcon({
96101
tabId: sender.tab.id,

packages/chrome-extension/src/detector.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,21 @@ function detect(win: Window) {
2626
return
2727
}
2828

29-
// 2. check Vue
29+
// 2. check VitePress
30+
// @ts-expect-error types
31+
const vitePressDetected = !!(window.__VITEPRESS__)
32+
if (vitePressDetected) {
33+
sendMessage({
34+
devtoolsEnabled: window.__VUE_DEVTOOLS_GLOBAL_HOOK__ && window.__VUE_DEVTOOLS_GLOBAL_HOOK__.enabled,
35+
vueDetected: true,
36+
vitePressDetected: true,
37+
vitePluginDetected: !!window.__VUE_DEVTOOLS_VITE_PLUGIN_DETECTED__,
38+
vitePluginClientUrl: window.__VUE_DEVTOOLS_VITE_PLUGIN_CLIENT_URL__,
39+
})
40+
return
41+
}
42+
43+
// 3. check Vue
3044
// @ts-expect-error types
3145
const vueDetected = !!(window.__VUE__)
3246
if (vueDetected) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<meta charset="utf-8" />
2+
<link rel="stylesheet" type="text/css" href="./popup.css" />
3+
4+
<p>
5+
<strong>VitePress + Vue.js is detected on this page.</strong><br />
6+
Devtools inspection is not available because it's in production mode or
7+
explicitly disabled by the author.
8+
</p>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<meta charset="utf-8" />
2+
<link rel="stylesheet" type="text/css" href="./popup.css" />
3+
4+
<div class="flex">
5+
<div class="screenshot">
6+
<img src="./devtools-screenshot.png" alt="Screenshot" />
7+
</div>
8+
9+
<div>
10+
<p>
11+
<strong>VitePress + Vue.js is detected on this page.</strong><br />
12+
Open DevTools and look for the Vue panel.
13+
</p>
14+
15+
<p>
16+
<a
17+
href="https://devtools-next.vuejs.org/help/troubleshooting"
18+
target="_blank"
19+
>Troubleshooting</a
20+
>
21+
</p>
22+
</div>
23+
</div>

packages/firefox-extension/src/background.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ chrome.runtime.onConnect.addListener((port) => {
8888

8989
chrome.runtime.onMessage.addListener((req, sender) => {
9090
if (sender.tab && req.vueDetected) {
91-
const suffix = req.nuxtDetected ? '.nuxt' : ''
91+
let suffix = ''
92+
93+
if (req.nuxtDetected)
94+
suffix = '.nuxt'
95+
else if (req.vitePressDetected)
96+
suffix = '.vitepress'
9297

9398
chrome.browserAction.setIcon({
9499
tabId: sender.tab.id,

0 commit comments

Comments
 (0)