Testcafe-hammerhead: Error: "TypeError: window.location.toString is not a function"

Created on 7 Nov 2019  路  2Comments  路  Source: DevExpress/testcafe-hammerhead

The issue has been reproduced here:
https://github.com/jsnanigans/hammerhead_testcafe_error

What is your Test Scenario?

Speculation: A iframe is focused, the iframe sends a message to the main window, the main window closes the iframe before testcafe can focus the main window.

A Iframe is opened where the user enters some data and clicks on submit, then the iframe is redirected with 307 to where some javascript sends a postMessage to our host window which closes the iframe. After the iframe is closed and this error occurs something in the redux dispatch or in the react core breaks and the state is not updated/the app is not re-rendered.
After some debugging we found that it might have something to do with hammerhead.js internals and some focus method.
Important things to note here are that this happens if the iframe has a src (like in this example) or has no src attribute (like in our application)

What is the Current behavior?

error is thrown and prevents react from rendering

What is the Expected behavior?

the main window is focused in testcafe and continues as usual

What is聽your web application and聽your TestCafe聽test code?

The issue has been reproduced here:
https://github.com/jsnanigans/hammerhead_testcafe_error

Steps to Reproduce:

  1. clone repo: https://github.com/jsnanigans/hammerhead_testcafe_error
  2. run npm install
  3. run npm start to start the local server on port 3000.
  4. run testcafe -c 1 chrome tests/Sample.ts --skip-js-errors to start testcafe.
  5. when the test stops for debugging, open the console in the browser, there you will see the error.

Your Environment details:

  • testcafe version: 1.6.1
  • node.js version: v12.11.1
  • command-line arguments: testcafe -c 1 chrome tests/Sample.ts --skip-js-errors
  • browser name and version: Google Chrome Version 78.0.3904.87 (Official Build) (64-bit)
  • platform and version: macOS 10.14.6 (18G103)
client level 2 event simulation iframe processing bug

Most helpful comment

Hello @jsnanigans ,

Thank you for submitting the issue. I've managed to reproduce it. We will research it and update this thread as soon as we have any results.

All 2 comments

Hello @jsnanigans ,

Thank you for submitting the issue. I've managed to reproduce it. We will research it and update this thread as soon as we have any results.

I've researched this issue and created a simplified example. The problem occurs when the focus method is called on some element from a removed iframe.

<body>
<script>
    var iframe = document.createElement('iframe');

    iframe.addEventListener('load', function () {
        var body = iframe.contentDocument.body;

        document.body.removeChild(iframe);
        body.focus();
    });

    document.body.appendChild(iframe);
</script>
VM2693 hammerhead.js:23480 Uncaught TypeError: window.location.toString is not a function
    at getLocation (VM2693 hammerhead.js:23480)
    at get (VM2693 hammerhead.js:23508)
    at Object.getParsed (VM2693 hammerhead.js:23523)
    at Function._wrapMessage (VM2693 hammerhead.js:13646)
    at MessageSandbox.sendServiceMsg (VM2693 hammerhead.js:13766)
    at ActiveWindowTracker.makeCurrentWindowActive (VM2693 hammerhead.js:11772)
    at raiseFocusEvent (VM2693 hammerhead.js:12664)
    at FocusBlurSandbox.focus (VM2693 hammerhead.js:12730)
    at HTMLBodyElement.focus (VM2693 hammerhead.js:13011)
    at HTMLIFrameElement.<anonymous> (iframe-focus.html:10)
Was this page helpful?
0 / 5 - 0 ratings