Skip to content

Commit c656192

Browse files
refactor: remove XDomainRequest support
This was used in IE8 (but behind a flag). BREAKING CHANGE: the enableXDR option is removed Related: #674
1 parent 00d7e7d commit c656192

File tree

9 files changed

+13
-128
lines changed

9 files changed

+13
-128
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ Exposed as `eio` in the browser standalone build.
227227
- `upgrade` (`Boolean`): defaults to true, whether the client should try
228228
to upgrade the transport from long-polling to something better.
229229
- `forceBase64` (`Boolean`): forces base 64 encoding for polling transport even when XHR2 responseType is available and WebSocket even if the used standard supports binary.
230-
- `enablesXDR` (`Boolean`): enables XDomainRequest for IE8 to avoid loading bar flashing with click sound. default to `false` because XDomainRequest has a flaw of not sending cookie.
231230
- `withCredentials` (`Boolean`): defaults to `false`, whether to include credentials (cookies, authorization headers, TLS client certificates, etc.) with cross-origin XHR polling requests.
232231
- `timestampRequests` (`Boolean`): whether to add the timestamp with each
233232
transport request. Note: polling requests are always stamped unless this

lib/socket.ts

-8
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,6 @@ export interface SocketOptions {
5353
*/
5454
forceBase64: boolean;
5555

56-
/**
57-
* Enables XDomainRequest for IE8 to avoid loading bar flashing with
58-
* click sound. default to `false` because XDomainRequest has a flaw
59-
* of not sending cookie.
60-
* @default false
61-
*/
62-
enablesXDR: boolean;
63-
6456
/**
6557
* The param name to use as our timestamp key
6658
* @default 't'

lib/transports/polling-xhr.ts

+12-37
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ export class Request extends Emitter {
148148
const opts = pick(
149149
this.opts,
150150
"agent",
151-
"enablesXDR",
152151
"pfx",
153152
"key",
154153
"passphrase",
@@ -196,27 +195,18 @@ export class Request extends Emitter {
196195
xhr.timeout = this.opts.requestTimeout;
197196
}
198197

199-
if (this.hasXDR()) {
200-
xhr.onload = () => {
198+
xhr.onreadystatechange = () => {
199+
if (4 !== xhr.readyState) return;
200+
if (200 === xhr.status || 1223 === xhr.status) {
201201
this.onLoad();
202-
};
203-
xhr.onerror = () => {
204-
this.onError(xhr.responseText);
205-
};
206-
} else {
207-
xhr.onreadystatechange = () => {
208-
if (4 !== xhr.readyState) return;
209-
if (200 === xhr.status || 1223 === xhr.status) {
210-
this.onLoad();
211-
} else {
212-
// make sure the `error` event handler that's user-set
213-
// does not throw in the same tick and gets caught here
214-
this.setTimeoutFn(() => {
215-
this.onError(typeof xhr.status === "number" ? xhr.status : 0);
216-
}, 0);
217-
}
218-
};
219-
}
202+
} else {
203+
// make sure the `error` event handler that's user-set
204+
// does not throw in the same tick and gets caught here
205+
this.setTimeoutFn(() => {
206+
this.onError(typeof xhr.status === "number" ? xhr.status : 0);
207+
}, 0);
208+
}
209+
};
220210

221211
debug("xhr data %s", this.data);
222212
xhr.send(this.data);
@@ -275,12 +265,7 @@ export class Request extends Emitter {
275265
if ("undefined" === typeof this.xhr || null === this.xhr) {
276266
return;
277267
}
278-
// xmlhttprequest
279-
if (this.hasXDR()) {
280-
this.xhr.onload = this.xhr.onerror = empty;
281-
} else {
282-
this.xhr.onreadystatechange = empty;
283-
}
268+
this.xhr.onreadystatechange = empty;
284269

285270
if (fromError) {
286271
try {
@@ -307,16 +292,6 @@ export class Request extends Emitter {
307292
}
308293
}
309294

310-
/**
311-
* Check if it has XDomainRequest.
312-
*
313-
* @api private
314-
*/
315-
hasXDR() {
316-
// @ts-ignore
317-
return typeof XDomainRequest !== "undefined" && !this.xs && this.enablesXDR;
318-
}
319-
320295
/**
321296
* Aborts the request.
322297
*

lib/xmlhttprequest.ts

-19
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,13 @@ import globalThis from "./globalThis.js";
66
export default function(opts) {
77
const xdomain = opts.xdomain;
88

9-
// scheme must be same when usign XDomainRequest
10-
// http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx
11-
const xscheme = opts.xscheme;
12-
13-
// XDomainRequest has a flow of not sending cookie, therefore it should be disabled as a default.
14-
// https://github.com/Automattic/engine.io-client/pull/217
15-
const enablesXDR = opts.enablesXDR;
16-
179
// XMLHttpRequest can be disabled on IE
1810
try {
1911
if ("undefined" !== typeof XMLHttpRequest && (!xdomain || hasCORS)) {
2012
return new XMLHttpRequest();
2113
}
2214
} catch (e) {}
2315

24-
// Use XDomainRequest for IE8 if enablesXDR is true
25-
// because loading bar keeps flashing when using jsonp-polling
26-
// https://github.com/yujiosaka/socke.io-ie8-loading-example
27-
try {
28-
// @ts-ignore
29-
if ("undefined" !== typeof XDomainRequest && !xscheme && enablesXDR) {
30-
// @ts-ignore
31-
return new XDomainRequest();
32-
}
33-
} catch (e) {}
34-
3516
if (!xdomain) {
3617
try {
3718
return new globalThis[["Active"].concat("Object").join("X")](

test/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ require("./engine.io-client");
1313
require("./socket");
1414
require("./transport");
1515
require("./connection");
16-
require("./transports");
1716
require("./xmlhttprequest");
1817

1918
if (typeof ArrayBuffer !== "undefined") {

test/support/env.js

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ exports.wsSupport = !!(
1414
const userAgent = typeof navigator !== "undefined" ? navigator.userAgent : "";
1515
exports.isOldSimulator =
1616
~userAgent.indexOf("iPhone OS 4") || ~userAgent.indexOf("iPhone OS 5");
17-
exports.isIE8 = /MSIE 8/.test(userAgent);
1817
exports.isIE9 = /MSIE 9/.test(userAgent);
1918
exports.isIE10 = /MSIE 10/.test(userAgent);
2019
exports.isIE11 = !!userAgent.match(/Trident.*rv[ :]*11\./); // ws doesn't work at all in sauce labs

test/transports/index.js

-1
This file was deleted.

test/transports/polling-xhr.js

-59
This file was deleted.

test/xmlhttprequest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const XMLHttpRequest = require("../build/cjs/xmlhttprequest").default;
33
const env = require("./support/env");
44

55
describe("XMLHttpRequest", () => {
6-
if (env.isIE8 || env.isIE9) {
6+
if (env.isIE9) {
77
describe("IE8_9", () => {
88
context("when xdomain is false", () => {
99
it("should have same properties as XMLHttpRequest does", () => {

0 commit comments

Comments
 (0)