Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(webkit): working around WebKit bug by patching Error #23588

Merged
merged 9 commits into from
Aug 31, 2022

Conversation

tbiethman
Copy link
Contributor

User facing changelog

N/A

Additional details

There were a few test cases within uncaught_errors.cy.js that were failing for the WebKit browser. The errors that were being thrown and uncaught within a Promise chain were not being received by Cypress. The root cause can be found documented within a WebKit bug report here; it shows a minimal reproduction, which I can confirm with my own findings.

A good bit of debugging and trial and error resulted in the work-around in this PR. It was found that any sort of operation executed after the Error was thrown would ensure that the proper error handlers would fire. A no-op microtask was chosen for this purpose, as it seems to have the smallest chance of impacting other functionality.

Steps to test

With this PR, all uncaught_errors specs will pass without any modification across our supported browsers.

How has the user experience changed?

PR Tasks

  • Have tests been added/updated?
  • Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • Has a PR for user-facing changes been opened in cypress-documentation?
  • Have API changes been updated in the type definitions?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Aug 29, 2022

Thanks for taking the time to open a PR!

@tbiethman tbiethman requested a review from flotwig August 29, 2022 14:16
let originalError = autWindow.Error

autWindow.Error = function (...args) {
autWindow.queueMicrotask(() => {})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this now, I wondered if this could backfire and cause an infinitely expanding queue, but I can't think of a scenario where that would happen where the user wouldn't already be doing infinite recursion anyways. So this seems safe enough...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I thought of one - if window.queueMicrotask is monkey-patched to throw an Error itself, this would infinitely recurse. But that seems unlikely to happen in the wild. Maybe we could name this function something like __CyWebKitError so that it's at least identifiable in a stack trace in case someone does run in to this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does seem unlikely, but naming the function is a good idea.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could even try...catch the queueMicrotask call... but... then that could also lead to really hard-to-debug issues ("why does my queueMicrotask monkey-patch make unhandled rejections not get caught by Cypress???"), so I think the way you have it is good for now. Let's see if any bug reports roll in.

packages/driver/src/cypress/cy.ts Outdated Show resolved Hide resolved
@cypress
Copy link

cypress bot commented Aug 29, 2022



Test summary

39665 0 3345 0Flakiness 1


Run details

Project cypress
Status Passed
Commit 9b370f3
Started Aug 31, 2022 2:23 PM
Ended Aug 31, 2022 2:38 PM
Duration 14:47 💡
OS Linux Debian - 11.3
Browser Multiple

View run in Cypress Dashboard ➡️


Flakiness

cypress/e2e/e2e/origin/basic_login.cy.ts Flakiness
1 ... > establishes a session

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@tbiethman tbiethman merged commit 212a055 into develop Aug 31, 2022
@tbiethman tbiethman deleted the tbiethman/webkit-unskip-tests branch August 31, 2022 14:48
@flotwig flotwig mentioned this pull request Sep 1, 2022
21 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants