Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useWebsocket in webworker:window in not defined #3937

Open
7 tasks done
sy19971224 opened this issue Apr 26, 2024 · 1 comment
Open
7 tasks done

useWebsocket in webworker:window in not defined #3937

sy19971224 opened this issue Apr 26, 2024 · 1 comment

Comments

@sy19971224
Copy link

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

@sy19971224
Copy link
Author

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) ---- 
}) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant