forked from vuejs/devtools-v6
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.js
More file actions
36 lines (30 loc) · 1.05 KB
/
proxy.js
File metadata and controls
36 lines (30 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// This is a content-script that is injected only when the devtools are
// activated. Because it is not injected using eval, it has full privilege
// to the chrome runtime API. It serves as a proxy between the injected
// backend and the Vue devtools panel.
const port = chrome.runtime.connect({
name: 'content-script',
})
port.onMessage.addListener(sendMessageToBackend)
window.addEventListener('message', sendMessageToDevtools)
port.onDisconnect.addListener(handleDisconnect)
sendMessageToBackend('init')
function sendMessageToBackend (payload) {
window.postMessage({
source: 'vue-devtools-proxy',
payload: payload,
}, '*')
}
function sendMessageToDevtools (e) {
if (e.data && e.data.source === 'vue-devtools-backend') {
port.postMessage(e.data.payload)
} else if (e.data && e.data.source === 'vue-devtools-backend-injection') {
if (e.data.payload === 'listening') {
sendMessageToBackend('init')
}
}
}
function handleDisconnect () {
window.removeEventListener('message', sendMessageToDevtools)
sendMessageToBackend('shutdown')
}