question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
LavrovArtemcommented, Mar 10, 2020

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)
Read more comments on GitHub >

github_iconTop Results From Across the Web

String is not a function on window location href - Stack Overflow
It is worth noting that window.location.href can be used as a function in both IE and Edge, just not other browsers (and it...
Read more >
window.location.href is not a function Error in JavaScript
The "window.location.href is not a function" error occurs when we try to invoke the href property on the window.location object.
Read more >
Tests started to fail with error message 'window.location ...
With 0.21.1, the tests are failing error log: Error: { type: 'uncaughtErrorOnPage', isTestC... ... toString is not a function', ...
Read more >
location.toString() - Web APIs - MDN Web Docs - Mozilla
The toString() stringifier method of the Location interface returns a string containing the whole URL. It is a read-only version of ...
Read more >
window.location Cheatsheet | SamanthaMing.com
The window.location object can be used to get information on the current page address (URL). You can also use its method to do...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found