Remove regex-based JS/HTML rewriting, switch to AST-based rewriting #7297
Open
Description
AST-based JS/HTML rewriting is available as an experimental feature with #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
- may require inlining
- (3) Do URL scheme not considered when deciding if origin has changed or not #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:cypress/packages/server/lib/util/inject.js
Lines 1 to 28 in 2ed5694
- (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 SIGABRT when calling
process.exit
withworker_threads
active electron/electron#23366 - (4) Fix all code TODOs from original PR: Rewrite JS/HTML using AST-based approach #5273