useWebsocket in webworker:window in not defined
sy19971224 opened this issue · comments
sy19971224 commented
Describe the bug
in work.js
,i used useWebsocket
,the socket connect successfully,but when i want to use the websocket
response data , an error message appears : window in not defined
here is my worker.js
import {useWebsocket} from @vueuse/core self.addEventlistener('message',(e) => { const {data} = useWebsocket(e.data.url,{ autoReconnect:{delay:3000}, onConnected:(ws) => { const sub = JSON.stringify({xxxx}) ws.send(sub) } }) // ----- error here : console.log(data) ---- })
Reproduction
none
System Info
npm:7.21.1
vue:2.7
vite:^3.1.3
vueuse/core:^7.5.3
Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a VueUse issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion.
- The provided reproduction is a minimal reproducible example of the bug.
sy19971224 commented
import {useWebsocket} from '@vueuse/core'
self.addEventlistener('message',(e) => {
const {data} = useWebsocket(e.data.url,{
autoReconnect:{delay:3000},
onConnected:(ws) => {
const sub = JSON.stringify({xxxx})
ws.send(sub)
}
})
// ----- error here : console.log(data) ----
})