Skip to content

Conversation

@alexsch01
Copy link
Contributor

@alexsch01 alexsch01 commented Dec 3, 2025

Additional details

Instead of trying to fit the injected cypress script into the head element, it's less error-prone to put it as a top level <script> tag before the HTML

  • one exception is the DOCTYPE, which needs to be the first line of text, so we are keeping insertAfter for that case

Original HTML

<!DOCTYPE html>
<html>
<!-- <head>
<title>Test</title> 
</head> -->
</html>

Before PR

<!DOCTYPE html>
<html>
<!-- <head> <script type='text/javascript'> CYPRESS_INJECTION(); </script>
<title>Test</title> 
</head> -->
</html>

After PR

<!DOCTYPE html>
<script type='text/javascript'> CYPRESS_INJECTION(); </script>
<html>
<!-- <head>
<title>Test</title> 
</head> -->
</html>

Steps to test

How has the user experience changed?

PR Tasks


Note

Switches HTML injection to place a top-level script before <html> (after DOCTYPE when present), adds robust DOCTYPE detection, and updates tests/fixtures accordingly.

  • Proxy HTML Rewriter:
    • Add robust doctypeRe to handle comments and optional XML prolog before <!DOCTYPE>.
    • Introduce htmlHelper and simplify html() to inject after DOCTYPE or prepend a top-level script before <html>; remove head/body/html insertion paths.
  • Tests:
    • Add unit tests for htmlHelper covering commented DOCTYPE/XML scenarios.
    • Update integration tests and fixtures to expect top-level script injection and adjusted document.domain injection order/output.
  • Changelog:
    • Note bugfix for commented HTML breaking DOM/script injection.

Written by Cursor Bugbot for commit ec0d1ad. This will update automatically on new commits. Configure here.

@cypress-app-bot
Copy link
Collaborator

@alexsch01 alexsch01 marked this pull request as draft December 5, 2025 05:52
@alexsch01 alexsch01 marked this pull request as ready for review December 5, 2025 12:04
@alexsch01
Copy link
Contributor Author

@jennifer-shehane @AtofStryker @mschile this is kinda a big change, let me know what you think of it
The regex isn't perfect, but I don't want a commented out DOCTYPE to be matched since that would cause the same issue this PR is fixing

@jennifer-shehane
Copy link
Member

@alexsch01 Going to run the tests

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.

commented HTML code prevents packages/proxy/lib/http/util/rewriter.ts from working properly

3 participants