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
This commit is contained in:
Cheng Zhao 2020-02-11 14:56:09 +09:00 committed by GitHub
parent 80dd16aa78
commit c608d6d7fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 897 additions and 59 deletions

View file

@ -0,0 +1,27 @@
<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>