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:
parent
80dd16aa78
commit
c608d6d7fb
14 changed files with 897 additions and 59 deletions
27
spec-main/fixtures/api/webrequest.html
Normal file
27
spec-main/fixtures/api/webrequest.html
Normal 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>
|
Loading…
Add table
Add a link
Reference in a new issue