testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

DataCloneError: Failed to execute 'postMessage' on 'Window':

Open sofilucky opened this issue 3 months ago • 11 comments

  1. A JavaScript error occurred on "Test Page". Repeat test actions in the browser and check the console for errors. Enable the “skipJsErrors” option to ignore JavaScript errors during test execution. Learn more:

"https://testcafe.io/documentation/404038/recipes/debugging/skip-javascript-errors" If the website only throws this error when you test it with TestCafe, please create a new issue at:

"https://github.com/DevExpress/testcafe/issues/new?template=bug-report.md".

  JavaScript error details:
  DataCloneError: Failed to execute 'postMessage' on 'Window': A
  MessagePort could not be cloned because it was not transferred.
      at fastApply (http://192.168.1.109:49606/hammerhead.js:20919:26)
      at MessageSandbox.postMessage
  (http://192.168.1.109:49606/hammerhead.js:41300:17)
      at http://192.168.1.109:49606/hammerhead.js:21024:71
      at

https://www.gstatic.com/recaptcha/releases/Jv8jlA-BQE5JD6rA-h_iqNH2/recaptcha__en.js:1294:338     at

https://www.gstatic.com/recaptcha/releases/Jv8jlA-BQE5JD6rA-h_iqNH2/recaptcha__en.js:1303:340

sofilucky avatar Oct 01 '25 13:10 sofilucky

I began seeing this same TestCafe/reCAPTCHA error this week. The error only occurs when the tests are run with TestCafe, not in the actual website.

willbiddy avatar Oct 01 '25 16:10 willbiddy

Thank you for submitting a bug report. We would love to help you investigate the issue. Please share a simple code example that reliably reproduces the bug. For more information, read the following article: How To Create a Minimal Working Example When You Submit an Issue. We look forward to your response.

github-actions[bot] avatar Oct 06 '25 07:10 github-actions[bot]

We have this as well and this is a minimal test that will make the error show:

import { Selector } from "testcafe";

fixture`Bug`;

test("test", async t => {
  await t.navigateTo("https://www.bjelin.se");
  await t.wait(10000);
  await t.expect(Selector("div#root").exists).ok();
});

Output:

Running tests in:
 - Chrome 140.0.0.0 / Windows 11
 Startup time (0.00s)

 Bug
 × test  (11s)

   1) A JavaScript error occurred on "https://www.bjelin.se/sv/".
      Repeat test actions in the browser and check the console for errors.
      Enable the “skipJsErrors” option to ignore JavaScript errors during test execution. Learn more: "https://testcafe.io/documentation/404038/recipes/debugging/skip-javascript-errors"
      If the website only throws this error when you test it with TestCafe, please create a new issue at:
      "https://github.com/DevExpress/testcafe/issues/new?template=bug-report.md".
      
      JavaScript error details:
      DataCloneError: Failed to execute 'postMessage' on 'Window': A MessagePort could not be cloned because it was not transferred.
          at fastApply (http://172.17.128.1:50915/hammerhead.js:20915:26)
          at MessageSandbox.postMessage (http://172.17.128.1:50915/hammerhead.js:41296:17)
          at http://172.17.128.1:50915/hammerhead.js:21020:71
          at https://www.gstatic.com/recaptcha/releases/bGi-DxR800F5_ueMVcTwXc6q/recaptcha__en.js:1320:703
          at https://www.gstatic.com/recaptcha/releases/bGi-DxR800F5_ueMVcTwXc6q/recaptcha__en.js:1329:287

      Browser: Chrome 140.0.0.0 / Windows 11


 Bug Duration (11s)

 1/1 failed (11s)

Our workaround for now has been to add a RequestMock in the testcaferc.js like this:

const disableRecaptcha = RequestMock()
  .onRequestTo(new RegExp("/recaptcha/releases"))
  .respond(undefined, 500, { 'access-control-allow-origin': '*' });

This will of course make the functions that actually call Recaptcha to fail with something like:

TypeError: m is not a function

This issue was automatically closed because there was no response to our request for more information from the original author. Currently, we don't have enough information to take action. Please reach out to us if you find the necessary information and are able to share it. We are also eager to know if you resolved the issue on your own and can share your findings with everyone.

github-actions[bot] avatar Oct 16 '25 08:10 github-actions[bot]

@aleks-pro I added a MWE above, please reopen

Hello @fredrikkarlsson-pervanovo ,

I created a simple project; however, I could not reproduce the issue with it. I have Windows 11, Chrome 141, and Node v20.19.5. Please review my sample and modify it to demonstrate the issue.

postMessage.zip

This way, I'll be in a better position to research the issue and give you precise recommendations.

Bayheck avatar Oct 22 '25 14:10 Bayheck

@Bayheck I can reproduce it with this: postMessage.zip

  • Added .testcaferc.cjs (disabling native automation, that seems to be part of it)
  • Added script to package.json

Run: npm run test

~~Ps. Also I run this with Node v20.12.2, but I don't think that's part of the issue. Will try to run on your version~~ Tested with v20.19.5 and still get:

Running tests in:
 - Chrome 141.0.0.0 / Windows 11

 Bug
 × test

   1) A JavaScript error occurred on "https://www.bjelin.se/sv/".
      Repeat test actions in the browser and check the console for errors.
      Enable the “skipJsErrors” option to ignore JavaScript errors during test execution. Learn more:
      "https://testcafe.io/documentation/404038/recipes/debugging/skip-javascript-errors"
      If the website only throws this error when you test it with TestCafe, please create a new issue at:
      "https://github.com/DevExpress/testcafe/issues/new?template=bug-report.md".

      JavaScript error details:
      DataCloneError: Failed to execute 'postMessage' on 'Window': A MessagePort could not be cloned because it was
      not transferred.
          at fastApply (http://192.168.150.2:56056/hammerhead.js:20919:26)
          at MessageSandbox.postMessage (http://192.168.150.2:56056/hammerhead.js:41300:17)
          at http://192.168.150.2:56056/hammerhead.js:21024:71
          at https://www.gstatic.com/recaptcha/releases/-PgDGgfmUF0ySmnjMTJjzqak/recaptcha__en.js:1319:2132
          at https://www.gstatic.com/recaptcha/releases/-PgDGgfmUF0ySmnjMTJjzqak/recaptcha__en.js:1326:291

      Browser: Chrome 141.0.0.0 / Windows 11

          3 |fixture`Bug`;
          4 |
          5 |test("test", async t => {
          6 |  await t.navigateTo("https://www.bjelin.se");
          7 |  await t.wait(10000);
       >  8 |  await t.debug();
          9 |  await t.expect(Selector("div#root").exists).ok();
         10 |});

         at <anonymous> (C:\Users\flomm\Desktop\postMessage\test.js:8:11)
         at asyncGeneratorStep (C:\Users\flomm\Desktop\postMessage\test.js:1:37)
         at _next (C:\Users\flomm\Desktop\postMessage\test.js:1:37)



 1/1 failed (12s)

Hello, I managed to run your example successfully with Native Automation mode enabled. Could you please describe why you use TestCafe with the "--disable-native-automation" flag?

Bayheck avatar Oct 23 '25 12:10 Bayheck

@Bayheck I run our test suite with native automation disabled since we have tests using multiform data that has (had?) a bug in chrome (https://github.com/DevExpress/testcafe/issues/7747). The only workaround has been to keep native automation disabled. I haven't tried to run the test suite with it enabled, so I guess I could try that.

I assume you could reproduce the error with native automation disabled then?

Hello, Yes, I managed to reproduce the issue with Native Automation disabled. I will reopen this issue.

Bayheck avatar Oct 27 '25 08:10 Bayheck

We appreciate you taking the time to share information about this issue. We reproduced the bug and added this ticket to our internal task queue. We'll update this thread once we have news.

github-actions[bot] avatar Oct 27 '25 08:10 github-actions[bot]