Skip to content

Commit ccec14a

Browse files
committed
fix(extension): inject scripts into html document only, close #904
1 parent d52c885 commit ccec14a

File tree

5 files changed

+33
-29
lines changed

5 files changed

+33
-29
lines changed

packages/chrome-extension/src/detector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,6 @@ function detect(win: Window) {
8080
}, 100)
8181
}
8282

83-
if (document instanceof Document) {
83+
if (document instanceof HTMLDocument) {
8484
detect(window)
8585
}
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
const body = document.getElementsByTagName('body')[0]
1+
if (document instanceof HTMLDocument) {
2+
const body = document.getElementsByTagName('body')[0]
23

3-
// create detector script
4-
const detector = document.createElement('script')
5-
detector.src = chrome.runtime.getURL('dist/detector.js')
6-
detector.onload = () => {
7-
detector.parentNode!.removeChild(detector)
8-
}
4+
// create detector script
5+
const detector = document.createElement('script')
6+
detector.src = chrome.runtime.getURL('dist/detector.js')
7+
detector.onload = () => {
8+
detector.parentNode!.removeChild(detector)
9+
}
910

10-
;(document.head || document.documentElement).appendChild(detector)
11+
;(document.head || document.documentElement).appendChild(detector)
1112

12-
window.addEventListener('message', (event) => {
13-
if (event.data.key === '__VUE_DEVTOOLS_VUE_DETECTED_EVENT__') {
14-
chrome.runtime.sendMessage(event.data.data)
15-
}
16-
}, false)
13+
window.addEventListener('message', (event) => {
14+
if (event.data.key === '__VUE_DEVTOOLS_VUE_DETECTED_EVENT__') {
15+
chrome.runtime.sendMessage(event.data.data)
16+
}
17+
}, false)
18+
}

packages/firefox-extension/src/detector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,6 @@ function detect(win: Window) {
8080
}, 100)
8181
}
8282

83-
if (document instanceof Document) {
83+
if (document instanceof HTMLDocument) {
8484
detect(window)
8585
}
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
const body = document.getElementsByTagName('body')[0]
1+
if (document instanceof HTMLDocument) {
2+
const body = document.getElementsByTagName('body')[0]
23

3-
// create detector script
4-
const detector = document.createElement('script')
5-
detector.src = chrome.runtime.getURL('dist/detector.js')
6-
detector.onload = () => {
7-
detector.parentNode!.removeChild(detector)
8-
}
4+
// create detector script
5+
const detector = document.createElement('script')
6+
detector.src = chrome.runtime.getURL('dist/detector.js')
7+
detector.onload = () => {
8+
detector.parentNode!.removeChild(detector)
9+
}
910

10-
;(document.head || document.documentElement).appendChild(detector)
11+
;(document.head || document.documentElement).appendChild(detector)
1112

12-
window.addEventListener('message', (event) => {
13-
if (event.data.key === '__VUE_DEVTOOLS_VUE_DETECTED_EVENT__') {
14-
chrome.runtime.sendMessage(event.data.data)
15-
}
16-
}, false)
13+
window.addEventListener('message', (event) => {
14+
if (event.data.key === '__VUE_DEVTOOLS_VUE_DETECTED_EVENT__') {
15+
chrome.runtime.sendMessage(event.data.data)
16+
}
17+
}, false)
18+
}

packages/firefox-extension/src/injection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if (document instanceof Document) {
1+
if (document instanceof HTMLDocument) {
22
const content = chrome.runtime.getURL('dist/prepare.js')
33
const script = document.createElement('script')
44
script.src = content

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy