yandeu / five-server-vscode

⚡ VSCode Extension for Five Server.
https://marketplace.visualstudio.com/items?itemName=yandeu.five-server
Other
121 stars 9 forks source link

WebSocket connection to 'wss://127.0.0.1:5500/fsws' failed #45

Open wideweide opened 1 year ago

wideweide commented 1 year ago

Describe the bug A clear and concise description of what the bug is.

try connect websocket then failed many times...

WebSocket connection to 'wss://127.0.0.1:5500/fsws' failed

Have a question? Join the discussions instead.

yandeu commented 1 year ago

Can you tell me what OS and Browser you use?

Do you use https?

wideweide commented 1 year ago

Can you tell me what OS and Browser you use?

Do you use https?

not use https,just http://127.0.0.1:5500/index.html ,but in browser console WebSocket connection to 'wss://127.0.0.1:5500/fsws' failed OS: pop! os (ubuntu) ,win11 browser: firefox /chrome

it seems some js error caused the error, some pure html page is work fine. my js has many code , I am not sure which code cause this. at last I found maybe iframe caused ,some code like here:

<script>
    function load(){
        document.getElementById('iT').src='examples/0001.html'
    }
</script>
<h1>test iframe </h1> 
<iframe id="iT" onload="load()"></iframe>

then


[Five Server] connecting...
VM428 fiveserver.js:1 [Five Server] connecting...
VM429 fiveserver.js:1 [Five Server] connecting...
VM430 fiveserver.js:1 [Five Server] connecting...
VM431 fiveserver.js:1 [Five Server] connecting...
VM431 fiveserver.js:1 [Five Server] status check...
VM432 fiveserver.js:1 [Five Server] connecting...
VM433 fiveserver.js:1 [Five Server] connecting...
VM433 fiveserver.js:1 [Five Server] status check...
VM434 fiveserver.js:1 [Five Server] connecting...
VM435 fiveserver.js:1 [Five Server] connecting...
VM436 fiveserver.js:1 [Five Server] connecting...
VM437 fiveserver.js:1 [Five Server] connecting...
yandeu commented 1 year ago

I see. Yes the error is from inside the iFrame.

Try to wait for five-server to connect:

<script>
  function load() {
    function run(e) {
      console.log('Some JavaScript Code...')
      document.getElementById('iT').src = 'examples/0001.html'
    }
    // wait for five-server to connect
    const five = document.querySelector('[data-id="five-server"]')
    if (five) five.addEventListener('connected', run)
    window.addEventListener('load', run)
  }
</script>
<h1>test iframe</h1>
<iframe id="iT" onload="load()"></iframe>