Skip to content

Conversation

@alexsch01
Copy link
Contributor

@alexsch01 alexsch01 commented Nov 20, 2025

  • Closes

Additional details

Steps to test

How has the user experience changed?

PR Tasks


Note

Injects the Cypress payload before a top‑level <script> appearing before <html>, adds unit tests for edge cases, and updates the changelog.

  • Proxy Rewriter (packages/proxy/lib/http/util/rewriter.ts)
    • Detects top‑level <script> before <html> and injects payload before it (scriptRe, isScriptTopLevel).
    • Updates html() to accept optional mockedHtmlToInject for testing and adjusts injection order.
  • Tests
    • Adds unit tests in packages/proxy/test/unit/http/util/rewriter.spec.ts covering top‑level and nested <script> scenarios.
  • Changelog
    • Adds bugfix entry noting improper injection when a <script> appears before <html> in cli/CHANGELOG.md.

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

@cypress-app-bot
Copy link
Collaborator

@jennifer-shehane
Copy link
Member

@alexsch01 Can you provide the failing example of this (just a static html file is fine even)? Curious how this problem manifests.

@alexsch01
Copy link
Contributor Author

alexsch01 commented Nov 20, 2025

@alexsch01 Can you provide the failing example of this (just a static html file is fine even)? Curious how this problem manifests.

I discovered this when manually testing #32925

<script>
  console.log(1, XMLHttpRequest.prototype.open.toString())
</script>

<html>
  <head>
    <script>
      console.log(2, XMLHttpRequest.prototype.open.toString())
    </script>
  </head>
</html>

the console log with 1 will be the original unmodified version
the console.log with 2 will be the patched version


I added a unit test

@alexsch01 alexsch01 changed the title fix: inject HTML before <script> if top-level fix: inject HTML before <script> if top-level Nov 20, 2025
@alexsch01 alexsch01 marked this pull request as draft November 21, 2025 02:20
@alexsch01 alexsch01 marked this pull request as ready for review November 21, 2025 11:15
@alexsch01 alexsch01 marked this pull request as draft November 21, 2025 11:20
@alexsch01
Copy link
Contributor Author

@jennifer-shehane if there's a commented <script> tag, this breaks, marking as draft

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.

3 participants