electron/spec-main/fixtures/api/webrequest.html
Cheng Zhao c608d6d7fb
fix: make webRequest work with WebSocket (#22040)
* fix: web request support proxying websocket

* fix: make tests work

* chore: do not use api:: code outside api/ folder

* chore: do not create proxy when no listener

* test: use separate session to avoid conflicts

* chore: address review
2020-02-11 14:56:09 +09:00

27 lines
631 B
HTML

<script>
var url = new URL(location.href)
const port = new URLSearchParams(url.search).get("port")
const ipcRenderer = require('electron').ipcRenderer
let count = 0
function checkFinish() {
count++
if (count === 2) {
ipcRenderer.send('websocket-success')
}
}
var conn = new WebSocket(`ws://127.0.0.1:${port}/websocket`)
conn.onopen = data => conn.send('foo')
conn.onmessage = wsMsg
function wsMsg(msg) {
if (msg.data === 'bar') {
checkFinish()
} else {
ipcRenderer.send('fail')
}
}
fetch(`http://127.0.0.1:${port}/`).then(() => {
checkFinish()
})
</script>