Skip to content

Commit 67171c3

Browse files
committed
fix: fix issue #21
1 parent 608905f commit 67171c3

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

.vscode/settings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"javascriptreact"
55
],
66
"editor.codeActionsOnSave": {
7-
"source.fixAll.eslint": true,
8-
"source.fixAll": true,
9-
"source.organizeImports": true
7+
"source.fixAll.eslint": "explicit",
8+
"source.fixAll": "explicit",
9+
"source.organizeImports": "explicit"
1010
},
1111
"editor.rulers": [120]
1212
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "http-request-mock",
3-
"version": "1.8.17",
3+
"version": "1.8.18",
44
"description": "Intercept & mock http requests issued by XMLHttpRequest, fetch, nodejs https/http module, axios, jquery, superagent, ky, node-fetch, request, got or any other request libraries by intercepting XMLHttpRequest, fetch and nodejs native requests in low level.",
55
"main": "src/index.js",
66
"module": "http-request-mock.esm.mjs",

src/interceptor/base.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,14 @@ export default class BaseInterceptor {
9090
if (/^https?:\/\//i.test(url)) {
9191
return this.checkProxyUrl(url, method);
9292
}
93+
9394
if (typeof URL === 'function' && typeof window === 'object' && window) {
94-
return this.checkProxyUrl(new URL(url, window.location.href).href, method);
95+
// https://github.com/huturen/http-request-mock/issues/21
96+
// "window.location.href" might point to an embedded file (e.g., data:text/html;charset=utf-8,...),
97+
// potentially leading to an "Invalid URL" error.
98+
if (/^https?:\/\//i.test(window.location.href)) {
99+
return this.checkProxyUrl(new URL(url, window.location.href).href, method);
100+
}
95101
}
96102

97103
if (typeof document === 'object' && document && typeof document.createElement === 'function') {

0 commit comments

Comments
 (0)