Skip to content

Commit a5095c6

Browse files
pi0Akryum
authored andcommitted
feat: detect Nuxt.js (#661)
* feat: add chrome shell icons for nuxt.js * feat: add chrome popups for nuxt.js * feat: support icon/popup suffix * feat(chrome/detector): add nuxt detector
1 parent 6ea0abf commit a5095c6

File tree

7 files changed

+37
-4
lines changed

7 files changed

+37
-4
lines changed

shells/chrome/icons/128.nuxt.png

3.94 KB
Loading

shells/chrome/icons/16.nuxt.png

487 Bytes
Loading

shells/chrome/icons/48.nuxt.png

1.42 KB
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<meta charset="utf-8">
2+
<p style="width: 200px">
3+
Nuxt.js + Vue.js is detected on this page.
4+
Devtools inspection is not available because it's in
5+
production mode or explicitly disabled by the author.
6+
</p>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<meta charset="utf-8">
2+
<p style="width: 180px;">
3+
Nuxt.js + Vue.js is detected on this page.
4+
Open DevTools and look for the Vue panel.
5+
</p>

shells/chrome/src/background.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,19 @@ function doublePipe (id, one, two) {
7878

7979
chrome.runtime.onMessage.addListener((req, sender) => {
8080
if (sender.tab && req.vueDetected) {
81+
const suffix = req.nuxtDetected ? '.nuxt' : ''
82+
8183
chrome.browserAction.setIcon({
8284
tabId: sender.tab.id,
8385
path: {
84-
16: 'icons/16.png',
85-
48: 'icons/48.png',
86-
128: 'icons/128.png'
86+
16: `icons/16${suffix}.png`,
87+
48: `icons/48${suffix}.png`,
88+
128: `icons/128${suffix}.png`
8789
}
8890
})
8991
chrome.browserAction.setPopup({
9092
tabId: sender.tab.id,
91-
popup: req.devtoolsEnabled ? 'popups/enabled.html' : 'popups/disabled.html'
93+
popup: req.devtoolsEnabled ? `popups/enabled${suffix}.html` : `popups/disabled${suffix}.html`
9294
})
9395
}
9496
})

shells/chrome/src/detector.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,26 @@ window.addEventListener('message', e => {
99

1010
function detect (win) {
1111
setTimeout(() => {
12+
// Method 1: Check Nuxt.js
13+
const nuxtDetected = Boolean(window.__NUXT__ || window.$nuxt)
14+
15+
if (nuxtDetected) {
16+
let Vue
17+
18+
if (window.$nuxt) {
19+
Vue = window.$nuxt.$root.constructor
20+
}
21+
22+
win.postMessage({
23+
devtoolsEnabled: Vue && Vue.config.devtools,
24+
vueDetected: true,
25+
nuxtDetected: true
26+
}, '*')
27+
28+
return
29+
}
30+
31+
// Method 2: Scan all elements inside document
1232
const all = document.querySelectorAll('*')
1333
let el
1434
for (let i = 0; i < all.length; i++) {

0 commit comments

Comments
 (0)