File size: 1,069 Bytes
4d70170 |
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 37 38 |
// 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,
}, '*')
}
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')
}
|