Skip to content

Commit 4faa354

Browse files
miherlosevVasilyStrelyaev
authored andcommitted
fix ''Invalid calling object' error appears in IE11 when active element is changed' (close #768). Bump version (#772)
* fix ''Invalid calling object' error appears in IE11 when active element is changed' (close #768) * update test * move comment to domUtils.getActiveElement, change calls 'document.activeElement' to 'domUtils.getActiveElement(document)'
1 parent 46c124f commit 4faa354

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "testcafe-hammerhead",
33
"description": "A powerful web-proxy used as a core for the TestCafe testing framework (https://github.com/DevExpress/testcafe).",
4-
"version": "9.3.3",
4+
"version": "9.3.4",
55
"homepage": "https://github.com/DevExpress/testcafe-hammerhead",
66
"bugs": {
77
"url": "https://github.com/DevExpress/testcafe-hammerhead/issues"

src/client/sandbox/event/focus-blur.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ export default class FocusBlurSandbox extends SandboxBase {
181181
this.activeWindowTracker.attach(window);
182182
this.topWindow = domUtils.isCrossDomainWindows(window, window.top) ? window : window.top;
183183

184-
this.listeners.addInternalEventListener(window, ['focus', 'blur'], () => this._onChangeActiveElement(this.document.activeElement));
184+
this.listeners.addInternalEventListener(window, ['focus', 'blur'], () => {
185+
var activeElement = domUtils.getActiveElement(this.document);
186+
187+
this._onChangeActiveElement(activeElement);
188+
});
185189
}
186190

187191
_callFocusCallback (callback, el) {
@@ -239,7 +243,7 @@ export default class FocusBlurSandbox extends SandboxBase {
239243

240244
// NOTE: If we call focus for an unfocusable element (like 'div' or 'image') in iframe, we should
241245
// specify document.active for this iframe manually, so we call focus without handlers.
242-
if (isElementInIframe && iframeElement && this.topWindow.document.activeElement !== iframeElement)
246+
if (isElementInIframe && iframeElement && domUtils.getActiveElement(this.topWindow.document) !== iframeElement)
243247
this._raiseEvent(iframeElement, 'focus', () => this._callFocusCallback(callback, el), true, isAsync);
244248
else
245249
this._callFocusCallback(callback, el);

src/client/utils/dom.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ function hasClassFallback (el, className) {
8080
}
8181

8282
export function getActiveElement (currentDocument) {
83+
// NOTE: Sometimes document.activeElement returns an empty object or null (IE11).
84+
// https://github.com/DevExpress/testcafe-hammerhead/issues/768
8385
var doc = currentDocument || document;
8486

85-
8687
return isDomElement(doc.activeElement) ? doc.activeElement : doc.body;
8788
}
8889

test/client/fixtures/sandbox/event/focus-blur-change-test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,3 +1042,42 @@ asyncTest('focus() must not raise the event if the element is in an invisible if
10421042

10431043
document.body.appendChild(iframe);
10441044
});
1045+
1046+
asyncTest('should correctly handle the case when document.activeElement is null or an empty object (GH-768)', function () {
1047+
expect(1);
1048+
1049+
var iframe = document.createElement('iframe');
1050+
var errorHandler = function () {
1051+
ok(false, 'error is reproduced');
1052+
};
1053+
1054+
window.addEventListener('error', errorHandler);
1055+
1056+
iframe.id = 'test_unique_id_02pog0ra5';
1057+
window.QUnitGlobals.waitForIframe(iframe)
1058+
.then(function () {
1059+
var iframeDocument = iframe.contentDocument;
1060+
var iframeWindow = iframe.contentWindow;
1061+
var div = iframeDocument.createElement('div');
1062+
var innerDiv = iframeDocument.createElement('div');
1063+
1064+
iframeWindow.addEventListener('focus', function () {
1065+
iframe.parentNode.removeChild(iframe);
1066+
window.removeEventListener('error', errorHandler);
1067+
ok(true, 'focus handler is called');
1068+
1069+
start();
1070+
}, true);
1071+
1072+
div.id = 'div';
1073+
innerDiv.id = 'innerDiv';
1074+
innerDiv.tabIndex = 0;
1075+
div.appendChild(innerDiv);
1076+
iframeDocument.body.appendChild(div);
1077+
1078+
innerDiv.focus();
1079+
div.innerHTML = '<span>Replaced</span>';
1080+
});
1081+
1082+
document.body.appendChild(iframe);
1083+
});

0 commit comments

Comments
 (0)