Skip to content

Commit

Permalink
feat(extension): add VitePress detector (#523)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyinws authored Jul 17, 2024
1 parent 12614a9 commit 555671f
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 4 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/chrome-extension/icons/16.vitepress.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/chrome-extension/icons/48.vitepress.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions packages/chrome-extension/popups/disabled.vitepress.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="./popup.css" />

<p>
<strong>VitePress + Vue.js is detected on this page.</strong><br />
Devtools inspection is not available because it's in production mode or
explicitly disabled by the author.
</p>
23 changes: 23 additions & 0 deletions packages/chrome-extension/popups/enabled.vitepress.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="./popup.css" />

<div class="flex">
<div class="screenshot">
<img src="./devtools-screenshot.png" alt="Screenshot" />
</div>

<div>
<p>
<strong>VitePress + Vue.js is detected on this page.</strong><br />
Open DevTools and look for the Vue panel.
</p>

<p>
<a
href="https://devtools-next.vuejs.org/help/troubleshooting"
target="_blank"
>Troubleshooting</a
>
</p>
</div>
</div>
7 changes: 6 additions & 1 deletion packages/chrome-extension/src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ chrome.runtime.onConnect.addListener((port) => {

chrome.runtime.onMessage.addListener((req, sender) => {
if (sender.tab && req.vueDetected) {
const suffix = req.nuxtDetected ? '.nuxt' : ''
let suffix = ''

if (req.nuxtDetected)
suffix = '.nuxt'
else if (req.vitePressDetected)
suffix = '.vitepress'

chrome.action.setIcon({
tabId: sender.tab.id,
Expand Down
16 changes: 15 additions & 1 deletion packages/chrome-extension/src/detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,21 @@ function detect(win: Window) {
return
}

// 2. check Vue
// 2. check VitePress
// @ts-expect-error types
const vitePressDetected = !!(window.__VITEPRESS__)
if (vitePressDetected) {
sendMessage({
devtoolsEnabled: window.__VUE_DEVTOOLS_GLOBAL_HOOK__ && window.__VUE_DEVTOOLS_GLOBAL_HOOK__.enabled,
vueDetected: true,
vitePressDetected: true,
vitePluginDetected: !!window.__VUE_DEVTOOLS_VITE_PLUGIN_DETECTED__,
vitePluginClientUrl: window.__VUE_DEVTOOLS_VITE_PLUGIN_CLIENT_URL__,
})
return
}

// 3. check Vue
// @ts-expect-error types
const vueDetected = !!(window.__VUE__)
if (vueDetected) {
Expand Down
8 changes: 8 additions & 0 deletions packages/firefox-extension/popups/disabled.vitepress.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="./popup.css" />

<p>
<strong>VitePress + Vue.js is detected on this page.</strong><br />
Devtools inspection is not available because it's in production mode or
explicitly disabled by the author.
</p>
23 changes: 23 additions & 0 deletions packages/firefox-extension/popups/enabled.vitepress.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="./popup.css" />

<div class="flex">
<div class="screenshot">
<img src="./devtools-screenshot.png" alt="Screenshot" />
</div>

<div>
<p>
<strong>VitePress + Vue.js is detected on this page.</strong><br />
Open DevTools and look for the Vue panel.
</p>

<p>
<a
href="https://devtools-next.vuejs.org/help/troubleshooting"
target="_blank"
>Troubleshooting</a
>
</p>
</div>
</div>
7 changes: 6 additions & 1 deletion packages/firefox-extension/src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ chrome.runtime.onConnect.addListener((port) => {

chrome.runtime.onMessage.addListener((req, sender) => {
if (sender.tab && req.vueDetected) {
const suffix = req.nuxtDetected ? '.nuxt' : ''
let suffix = ''

if (req.nuxtDetected)
suffix = '.nuxt'
else if (req.vitePressDetected)
suffix = '.vitepress'

chrome.browserAction.setIcon({
tabId: sender.tab.id,
Expand Down
16 changes: 15 additions & 1 deletion packages/firefox-extension/src/detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,21 @@ function detect(win: Window) {
return
}

// 2. check Vue
// 2. check VitePress
// @ts-expect-error types
const vitePressDetected = !!(window.__VITEPRESS__)
if (vitePressDetected) {
sendMessage({
devtoolsEnabled: window.__VUE_DEVTOOLS_GLOBAL_HOOK__ && window.__VUE_DEVTOOLS_GLOBAL_HOOK__.enabled,
vueDetected: true,
vitePressDetected: true,
vitePluginDetected: !!window.__VUE_DEVTOOLS_VITE_PLUGIN_DETECTED__,
vitePluginClientUrl: window.__VUE_DEVTOOLS_VITE_PLUGIN_CLIENT_URL__,
})
return
}

// 3. check Vue
// @ts-expect-error types
const vueDetected = !!(window.__VUE__)
if (vueDetected) {
Expand Down

0 comments on commit 555671f

Please sign in to comment.