From 9b88aaca432caa6f6607b65a9a0426b220a3308b Mon Sep 17 00:00:00 2001 From: redhoodsu Date: Tue, 15 Oct 2024 17:32:31 +0800 Subject: [PATCH] fix: fetch error keep pending --- .eslintrc.js | 21 ------ .eslintrc.json | 25 +++++++ devtools/network.js | 39 +++++++++++ devtools/target.html | 19 ------ devtools/target.js | 45 ++++++------- package.json | 4 +- src/domains/Network.ts | 144 +++++++++++++++++------------------------ src/lib/request.ts | 69 +++++++++++++------- 8 files changed, 195 insertions(+), 171 deletions(-) delete mode 100644 .eslintrc.js create mode 100644 .eslintrc.json create mode 100644 devtools/network.js diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index c64da99..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,21 +0,0 @@ -module.exports = { - root: true, - env: { - browser: true, - node: true, - }, - parser: '@typescript-eslint/parser', - plugins: ['@typescript-eslint'], - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/recommended', - 'prettier', - ], - rules: { - '@typescript-eslint/no-explicit-any': 'off', - 'prefer-rest-params': 'off', - '@typescript-eslint/no-this-alias': 'off', - '@typescript-eslint/no-var-requires': 'off', - 'prefer-spread': 'off', - }, -} diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..ebe44d6 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,25 @@ +{ + "root": true, + "env": { + "browser": true, + "node": true + }, + "parser": "@typescript-eslint/parser", + "plugins": [ + "@typescript-eslint" + ], + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "prettier" + ], + "rules": { + "@typescript-eslint/no-explicit-any": "off", + "prefer-rest-params": "off", + "@typescript-eslint/no-this-alias": "off", + "@typescript-eslint/no-var-requires": "off", + "@typescript-eslint/no-require-imports": "off", + "@typescript-eslint/no-unused-vars": "off", + "prefer-spread": "off" + } +} diff --git a/devtools/network.js b/devtools/network.js new file mode 100644 index 0000000..ea1a46a --- /dev/null +++ b/devtools/network.js @@ -0,0 +1,39 @@ +setTimeout(function () { + fetch(location.href) +}, 1000) + +function testFetch() { + fetch('/index.js') + fetch('https://domainnotexist.com').catch(err => { + console.error(err) + }) +} + +function testXhr() { + let xhr = new XMLHttpRequest() + xhr.open('GET', '/index.js', true) + xhr.send() + + xhr = new XMLHttpRequest() + xhr.open('GET', 'https://domainnotexist.com', true) + xhr.send() +} + +function testWs() { + const text = 'This is the text used for testing!' + + const enc = new TextEncoder() + const ws = new WebSocket('wss://echo.websocket.org') + + ws.onopen = function () { + ws.send(text) + ws.send(enc.encode(text)) + } + setTimeout(() => { + ws.close() + }, 1000) +} + +testFetch() +testXhr() +testWs() diff --git a/devtools/target.html b/devtools/target.html index 1b35984..8a794d5 100644 --- a/devtools/target.html +++ b/devtools/target.html @@ -86,27 +86,8 @@ console.log('Page loaded!') setTimeout(function () { console.log('Hello Chii') - fetch(location.href) }, 1000) -