-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Interceptors would try to handle `data:` url's
- Loading branch information
1 parent
1493c12
commit 217e861
Showing
4 changed files
with
35 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
import { parseRelativeUrl } from '../../utils'; | ||
import * as logger from '../../utils/logger'; | ||
import { nativeXMLHttpRequestOpen } from './natives'; | ||
|
||
export default function attach(onXhrOpenCalled) { | ||
XMLHttpRequest.prototype.open = function(method, url) { | ||
XMLHttpRequest.prototype.open = function(...args) { | ||
let [method, url] = args; | ||
try { | ||
let parsedUrl = parseRelativeUrl(url); | ||
if (typeof url === 'string') { | ||
if (url.indexOf('/') === 0) { | ||
url = window.location.origin + url; | ||
} | ||
|
||
if (parsedUrl) { | ||
const modifiedUrl = onXhrOpenCalled(method, parsedUrl, this); | ||
if (url.indexOf('https://') !== -1) { | ||
const modifiedUrl = onXhrOpenCalled(method, url, this); | ||
|
||
if (modifiedUrl) { | ||
arguments[1] = modifiedUrl.toString(); | ||
if (modifiedUrl) { | ||
args[1] = modifiedUrl; | ||
} | ||
} | ||
} | ||
} catch (err) { | ||
logger.error(err, `Failed to intercept XMLHttpRequest.open()`); | ||
} | ||
|
||
nativeXMLHttpRequestOpen.apply(this, arguments); | ||
nativeXMLHttpRequestOpen.apply(this, args); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters