testcafe: Safari: Uncaught object "[object Object]" was thrown. Throw Error instead.

What is your Test Scenario?

This error occurs on a number of tests… but the easiest one is navigating to a url that redirects.

What is the Current behavior?

Similar to #6593, I’m getting an uncaught object error in Safari. I’m suppressing JS errors and uncaught errors… but my tests are still failing.

What is the Expected behavior?

I can navigate to the desired page, and no error is thrown once the page loads

What is your web application and your TestCafe test code?

Your website URL (or attach your complete example):
Your complete test code (or attach your test files):
 import { Selector } from 'testcafe';

fixture('Navigate to petition page, non-promoteable petition').page('https://www.change.org/');

test('Ensure promotion page does not show', async t => {
  await t
    .navigateTo('/p/united-nations-send-matt-damon-to-mars-to-retrieve-opportunity/sponsors/new')
    .expect(Selector('[data-testid="signform-submit-button"]').visible)
    .ok();
});
Your complete configuration file (if any):
{
  "src": "./tests/**/*.js",
  "clientScripts":[
    {
      "module":"axe-core/axe.min.js"
    }
  ],

  "assertionTimeout": 15000,
  "ajaxRequestTimeout": 40000,
  "pageLoadTimeout": 30000,
  "selectorTimeout": 15000,

  "disableMultipleWindows": false,

  "quarantineMode": false,
  "skipJsErrors": true,

  "disablePageCaching": true,

  "reporter": [
    {
      "name": "xunit",
      "output": "artifacts/test-results/results.xml"
    },
    {
      "name": "spec"
    }
  ],

  "screenshots": {
    "fullPage": true,
    "takeOnFails": true,
    "pathPattern": "${TEST_ID}/${RUN_ID}_${FILE_INDEX}.png",
    "path": "artifacts/screenshots",
    "thumbnails": false
  }
}
Your complete test report:
   1) Uncaught object "[object Object]" was thrown. Throw Error instead.

      Browser: Safari 15.0 / macOS 10.15.7
      Screenshot: /Users/rcooper/work/github.com/change/regression-qaa/artifacts/screenshots/test-1/_errors/1.png

Screenshots:
https://user-images.githubusercontent.com/37812673/137813141-419be9a1-af3c-4f8e-8bfa-0b7be28b96e8.png

Steps to Reproduce:

  1. Go to my website …
  2. Execute this command…
  3. See the error…

Your Environment details:

  • testcafe version: 1.16.1
  • node.js version: 14.16.1
  • command-line arguments: testcafe safari -u
  • browser name and version: Safari 15.0
  • platform and version: macOS 10.15.7
  • other:

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (5 by maintainers)

Commits related to this issue

Most upvoted comments

@danieltroger

Hello,

Thank you for your research, we’ll review @rob4629’s PR.

I tried to prepare a pull request but I’m failing at creating a test case because it’s impossible to install IE11 and I’m running macOS: Error: Cannot find the browser. "ie" is neither a known browser alias, nor a path to an executable file.

But I made a patch instead that you can use to fix the error locally while we’re waiting for testcafe @rob4629:

testcafe_fix_6624.patch.zip

Put this into your package.json:

"resolutions": {
    "testcafe": "patch:testcafe@latest#./patches/testcafe_fix_6624.patch"
  }

unzip the file and put it into a folder called patches relative to your package.json and run yarn install You might have to replace latest in the resolution with whatever version you have pinned of testcafe.

Generated with https://yarnpkg.com/cli/patch and works with yarn 3.1.0

Hey,

It’s 10pm and I’m still at work because I debugged, I think, this issue. Sorry for this message being bad and stuff I just want to go home.

I’m getting this error in safari:

  1) Uncaught object "[object Object]" was thrown. Throw Error instead.

      Browser: Safari 15.1 / macOS 10.15.7

I think it is the same issue?

I tracked it down during the last 3 hours:

The service worker on the site sends a payload to the “backend” looking like this

Screenshot 2021-11-22 at 20 14 10

with executionError being an empty object (it’s supposed to be null), that makes the backend throw an error.

In the backend, it has a very misleading stack trace pointing essentially to the test code file itself, but that’s this one with the head cut off (I think): Screenshot 2021-11-22 at 19 27 32

This is because at this place the current place in the code is used if no callstack is recieved from the frontend: Screenshot 2021-11-22 at 20 13 59

On the frontend, the message containing the executionError empty object is passed to the service worker by some code reading sessionStorage.

On the page load before the load where that is sent, an exception is thrown and written to the sessionStorage. However, it is not properly serialized - only by JSON.parse, which just turns it into an empty object.

Proof: Screenshot 2021-11-22 at 21 58 19

The actual error has the following .stack property: Screenshot 2021-11-22 at 21 58 52

Reading that stack trace, the error is thrown here: Screenshot 2021-11-22 at 21 59 29

And originates from here (the call to Nt): Screenshot 2021-11-22 at 22 01 38

Which is this part in the original, unminfied code (Promise$3):

Screenshot 2021-11-22 at 22 02 10

This shows us that it’s probably a minification error. Something has stripped the new keyword, making the call to the Promise constructor fail. It’s either a bug in the minifier that was used or a configuration mistake.

@Farfurix I would be grateful if you could:

  1. Confirm that I have posted this in the correct issue
  2. Tell me which minifier you’re using and how I can reproduce the builds to try to fix it, alternatively fix it in a timely manner. I think it should be easy for you from now on 😃
  3. Make proper serialisation of errors going from the frontend to the backend so that nobody has to go through this debugging journey ever again

Thanks ❤️

@rob4629

Hello,

I reproduced this issue. We will update this thread once we have any news.