question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove regex-based JS/HTML rewriting, switch to AST-based rewriting

See original GitHub issue

AST-based JS/HTML rewriting is available as an experimental feature with https://github.com/cypress-io/cypress/pull/5273

Here are the remaining tasks before it can fully replace the existing regex-based rewriting:

  • Validation with users - is it solving the issues we set out to fix?
  • (2) Rewrite all traffic (currently, only AUT’s current origin is intercepted)
    • may require inlining resolvers.ts
  • (3) Do https://github.com/cypress-io/cypress/issues/7268 or have it be fixed by inlining resolvers.ts
    • or else rewriting will break if a user visits an http:// url that redirects to https://
  • (4) Inject HTML via parse5 instead of regex.
  • (4) Resolve issue where proxy will no longer work for normal web browsing outside of Cypress frame. Possible solution: inject a stub window.Cypress.resolveWindowReference into every html page here: https://github.com/cypress-io/cypress/blob/2ed56949cb14b4630ca11ec8c4cda715aa9bfa26/packages/server/lib/util/inject.js#L1-L28
  • (4) Performance measurements:
    • difference between rewriting with sourcemap and without
    • comparison to regex-based rewriting
  • (4) Performance improvements:
    • improve speed: add streaming parsing/rewriting of JS (parse5 handles rewriting HTML as a stream)
    • mem usage: explore caching js in deferred-sourcemap-cache on filesystem
    • understand how sourcemaps are cached in browser and how we can reduce unnecessary regeneration/not store old sourcemaps in RAM
  • (4) Add comments around injected code to help users understand - potentially include original code in a comment
  • (1) Need a real fix for Electron worker_threads https://github.com/electron/electron/issues/23366
  • (4) Fix all code TODOs from original PR: https://github.com/cypress-io/cypress/pull/5273

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
drumbegcommented, Jun 9, 2020

4.8.0 looking good 👍

0reactions
flotwigcommented, Jun 3, 2020

@drumbeg yeah, just merged that PR; it may fix the issue for you once released

Read more comments on GitHub >

github_iconTop Results From Across the Web

Experiments | Cypress Documentation
Enables AST-based JS/HTML rewriting. This may fix issues caused by the existing regex-based JS/HTML replacement algorithm. See #5273 for details.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found