mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 22:40:01 -04:00
Merge branch 'main' of https://github.com/MercuryWorkshop/scramjet
This commit is contained in:
commit
7bea0c60af
20 changed files with 359 additions and 248 deletions
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
<a href="https://www.npmjs.com/package/@mercuryworkshop/scramjet"><img src="https://img.shields.io/npm/v/@mercuryworkshop/scramjet.svg?maxAge=3600" alt="npm version" /></a>
|
<a href="https://www.npmjs.com/package/@mercuryworkshop/scramjet"><img src="https://img.shields.io/npm/v/@mercuryworkshop/scramjet.svg?maxAge=3600" alt="npm version" /></a>
|
||||||
|
|
||||||
Scramjet is an experimental inteception based web proxy that aims to be the successor to Ultraviolet. It is designed with security, developer friendlyness, and performance in mind. Scramjet strives to have a clean, organized codebase to improve maintainability. Scramjet is made to evade internet censorship and bypass arbitrary web browser restrictions.
|
Scramjet is an experimental interception based web proxy that aims to be the successor to Ultraviolet. It is designed with security, developer friendliness, and performance in mind. Scramjet strives to have a clean, organized codebase to improve maintainability. Scramjet is made to evade internet censorship and bypass arbitrary web browser restrictions.
|
||||||
|
|
||||||
## Supported Sites
|
## Supported Sites
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ Some of the popular websites that Scramjet supports include:
|
||||||
#### Building
|
#### Building
|
||||||
|
|
||||||
- Clone the repository with `git clone --recursive https://github.com/MercuryWorkshop/scramjet`
|
- Clone the repository with `git clone --recursive https://github.com/MercuryWorkshop/scramjet`
|
||||||
- Then, install your dependencies with `pnpm i`
|
- Then, install the dependencies with `pnpm i`
|
||||||
- After, build the rewriter with `pnpm rewriter:build`
|
- After, build the rewriter with `pnpm rewriter:build`
|
||||||
- Finally, build Scramjet with `pnpm build`
|
- Finally, build Scramjet with `pnpm build`
|
||||||
|
|
||||||
|
|
13
codespace-basic-setup.sh
Normal file
13
codespace-basic-setup.sh
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
||||||
|
source "$HOME/.cargo/env" # to import rustup in current shell
|
||||||
|
pnpm i
|
||||||
|
cargo install wasm-bindgen-cli
|
||||||
|
VER=$(curl --silent -qI https://github.com/WebAssembly/binaryen/releases/latest | awk -F '/' '/^location/ {print substr($NF, 1, length($NF)-1)}'); \
|
||||||
|
curl -LO https://github.com/WebAssembly/binaryen/releases/download/$VER/binaryen-${VER}-x86_64-linux.tar.gz
|
||||||
|
tar xvf binaryen-${VER}-x86_64-linux.tar.gz
|
||||||
|
rm -rf binaryen-${VER}-x86_64-linux.tar.gz
|
||||||
|
mv binaryen-${VER}/bin/* ~/.local/bin
|
||||||
|
mv binaryen-${VER}/lib/* ~/.local/lib
|
||||||
|
rm -rf binaryen-${VER}
|
||||||
|
pnpm rewriter:build
|
||||||
|
pnpm build
|
|
@ -40,7 +40,7 @@
|
||||||
"@rspack/core": "^1.0.13",
|
"@rspack/core": "^1.0.13",
|
||||||
"@types/eslint": "^9.6.1",
|
"@types/eslint": "^9.6.1",
|
||||||
"@types/estree": "^1.0.6",
|
"@types/estree": "^1.0.6",
|
||||||
"@types/node": "^22.7.7",
|
"@types/node": "^22.7.8",
|
||||||
"@types/serviceworker": "^0.0.101",
|
"@types/serviceworker": "^0.0.101",
|
||||||
"@typescript-eslint/eslint-plugin": "^8.11.0",
|
"@typescript-eslint/eslint-plugin": "^8.11.0",
|
||||||
"@typescript-eslint/parser": "^8.11.0",
|
"@typescript-eslint/parser": "^8.11.0",
|
||||||
|
|
|
@ -7,7 +7,7 @@ export default defineConfig({
|
||||||
testDir: "./tests",
|
testDir: "./tests",
|
||||||
fullyParallel: true,
|
fullyParallel: true,
|
||||||
forbidOnly: !!process.env.CI,
|
forbidOnly: !!process.env.CI,
|
||||||
retries: 0,
|
retries: 2,
|
||||||
reporter: "html",
|
reporter: "html",
|
||||||
timeout: 20000,
|
timeout: 20000,
|
||||||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
||||||
|
|
44
pnpm-lock.yaml
generated
44
pnpm-lock.yaml
generated
|
@ -67,8 +67,8 @@ importers:
|
||||||
specifier: ^1.0.6
|
specifier: ^1.0.6
|
||||||
version: 1.0.6
|
version: 1.0.6
|
||||||
'@types/node':
|
'@types/node':
|
||||||
specifier: ^22.7.7
|
specifier: ^22.7.8
|
||||||
version: 22.7.7
|
version: 22.7.8
|
||||||
'@types/serviceworker':
|
'@types/serviceworker':
|
||||||
specifier: ^0.0.101
|
specifier: ^0.0.101
|
||||||
version: 0.0.101
|
version: 0.0.101
|
||||||
|
@ -451,8 +451,8 @@ packages:
|
||||||
'@types/node-forge@1.3.11':
|
'@types/node-forge@1.3.11':
|
||||||
resolution: {integrity: sha512-FQx220y22OKNTqaByeBGqHWYz4cl94tpcxeFdvBo3wjG6XPBuZ0BNgNZRV5J5TFmmcsJ4IzsLkmGRiQbnYsBEQ==}
|
resolution: {integrity: sha512-FQx220y22OKNTqaByeBGqHWYz4cl94tpcxeFdvBo3wjG6XPBuZ0BNgNZRV5J5TFmmcsJ4IzsLkmGRiQbnYsBEQ==}
|
||||||
|
|
||||||
'@types/node@22.7.7':
|
'@types/node@22.7.8':
|
||||||
resolution: {integrity: sha512-SRxCrrg9CL/y54aiMCG3edPKdprgMVGDXjA3gB8UmmBW5TcXzRUYAh8EWzTnSJFAd1rgImPELza+A3bJ+qxz8Q==}
|
resolution: {integrity: sha512-a922jJy31vqR5sk+kAdIENJjHblqcZ4RmERviFsER4WJcEONqxKcjNOlk0q7OUfrF5sddT+vng070cdfMlrPLg==}
|
||||||
|
|
||||||
'@types/qs@6.9.16':
|
'@types/qs@6.9.16':
|
||||||
resolution: {integrity: sha512-7i+zxXdPD0T4cKDuxCUXJ4wHcsJLwENa6Z3dCu8cfCK743OGy5Nu1RmAGqDPsoTDINVEcdXKRvR/zre+P2Ku1A==}
|
resolution: {integrity: sha512-7i+zxXdPD0T4cKDuxCUXJ4wHcsJLwENa6Z3dCu8cfCK743OGy5Nu1RmAGqDPsoTDINVEcdXKRvR/zre+P2Ku1A==}
|
||||||
|
@ -2816,26 +2816,26 @@ snapshots:
|
||||||
'@types/body-parser@1.19.5':
|
'@types/body-parser@1.19.5':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/connect': 3.4.38
|
'@types/connect': 3.4.38
|
||||||
'@types/node': 22.7.7
|
'@types/node': 22.7.8
|
||||||
|
|
||||||
'@types/bonjour@3.5.13':
|
'@types/bonjour@3.5.13':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/node': 22.7.7
|
'@types/node': 22.7.8
|
||||||
|
|
||||||
'@types/connect-history-api-fallback@1.5.4':
|
'@types/connect-history-api-fallback@1.5.4':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/express-serve-static-core': 5.0.0
|
'@types/express-serve-static-core': 5.0.0
|
||||||
'@types/node': 22.7.7
|
'@types/node': 22.7.8
|
||||||
|
|
||||||
'@types/connect@3.4.38':
|
'@types/connect@3.4.38':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/node': 22.7.7
|
'@types/node': 22.7.8
|
||||||
|
|
||||||
'@types/cookie@0.4.1': {}
|
'@types/cookie@0.4.1': {}
|
||||||
|
|
||||||
'@types/cors@2.8.17':
|
'@types/cors@2.8.17':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/node': 22.7.7
|
'@types/node': 22.7.8
|
||||||
|
|
||||||
'@types/eslint@9.6.1':
|
'@types/eslint@9.6.1':
|
||||||
dependencies:
|
dependencies:
|
||||||
|
@ -2848,14 +2848,14 @@ snapshots:
|
||||||
|
|
||||||
'@types/express-serve-static-core@4.19.6':
|
'@types/express-serve-static-core@4.19.6':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/node': 22.7.7
|
'@types/node': 22.7.8
|
||||||
'@types/qs': 6.9.16
|
'@types/qs': 6.9.16
|
||||||
'@types/range-parser': 1.2.7
|
'@types/range-parser': 1.2.7
|
||||||
'@types/send': 0.17.4
|
'@types/send': 0.17.4
|
||||||
|
|
||||||
'@types/express-serve-static-core@5.0.0':
|
'@types/express-serve-static-core@5.0.0':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/node': 22.7.7
|
'@types/node': 22.7.8
|
||||||
'@types/qs': 6.9.16
|
'@types/qs': 6.9.16
|
||||||
'@types/range-parser': 1.2.7
|
'@types/range-parser': 1.2.7
|
||||||
'@types/send': 0.17.4
|
'@types/send': 0.17.4
|
||||||
|
@ -2870,27 +2870,27 @@ snapshots:
|
||||||
'@types/fs-extra@11.0.4':
|
'@types/fs-extra@11.0.4':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/jsonfile': 6.1.4
|
'@types/jsonfile': 6.1.4
|
||||||
'@types/node': 22.7.7
|
'@types/node': 22.7.8
|
||||||
|
|
||||||
'@types/http-errors@2.0.4': {}
|
'@types/http-errors@2.0.4': {}
|
||||||
|
|
||||||
'@types/http-proxy@1.17.15':
|
'@types/http-proxy@1.17.15':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/node': 22.7.7
|
'@types/node': 22.7.8
|
||||||
|
|
||||||
'@types/json-schema@7.0.15': {}
|
'@types/json-schema@7.0.15': {}
|
||||||
|
|
||||||
'@types/jsonfile@6.1.4':
|
'@types/jsonfile@6.1.4':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/node': 22.7.7
|
'@types/node': 22.7.8
|
||||||
|
|
||||||
'@types/mime@1.3.5': {}
|
'@types/mime@1.3.5': {}
|
||||||
|
|
||||||
'@types/node-forge@1.3.11':
|
'@types/node-forge@1.3.11':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/node': 22.7.7
|
'@types/node': 22.7.8
|
||||||
|
|
||||||
'@types/node@22.7.7':
|
'@types/node@22.7.8':
|
||||||
dependencies:
|
dependencies:
|
||||||
undici-types: 6.19.8
|
undici-types: 6.19.8
|
||||||
|
|
||||||
|
@ -2905,7 +2905,7 @@ snapshots:
|
||||||
'@types/send@0.17.4':
|
'@types/send@0.17.4':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/mime': 1.3.5
|
'@types/mime': 1.3.5
|
||||||
'@types/node': 22.7.7
|
'@types/node': 22.7.8
|
||||||
|
|
||||||
'@types/serve-index@1.9.4':
|
'@types/serve-index@1.9.4':
|
||||||
dependencies:
|
dependencies:
|
||||||
|
@ -2914,14 +2914,14 @@ snapshots:
|
||||||
'@types/serve-static@1.15.7':
|
'@types/serve-static@1.15.7':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/http-errors': 2.0.4
|
'@types/http-errors': 2.0.4
|
||||||
'@types/node': 22.7.7
|
'@types/node': 22.7.8
|
||||||
'@types/send': 0.17.4
|
'@types/send': 0.17.4
|
||||||
|
|
||||||
'@types/serviceworker@0.0.101': {}
|
'@types/serviceworker@0.0.101': {}
|
||||||
|
|
||||||
'@types/sockjs@0.3.36':
|
'@types/sockjs@0.3.36':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/node': 22.7.7
|
'@types/node': 22.7.8
|
||||||
|
|
||||||
'@types/tapable@2.2.7':
|
'@types/tapable@2.2.7':
|
||||||
dependencies:
|
dependencies:
|
||||||
|
@ -2929,7 +2929,7 @@ snapshots:
|
||||||
|
|
||||||
'@types/ws@8.5.12':
|
'@types/ws@8.5.12':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/node': 22.7.7
|
'@types/node': 22.7.8
|
||||||
|
|
||||||
'@typescript-eslint/eslint-plugin@8.11.0(@typescript-eslint/parser@8.11.0(eslint@9.13.0)(typescript@5.6.3))(eslint@9.13.0)(typescript@5.6.3)':
|
'@typescript-eslint/eslint-plugin@8.11.0(@typescript-eslint/parser@8.11.0(eslint@9.13.0)(typescript@5.6.3))(eslint@9.13.0)(typescript@5.6.3)':
|
||||||
dependencies:
|
dependencies:
|
||||||
|
@ -3480,7 +3480,7 @@ snapshots:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/cookie': 0.4.1
|
'@types/cookie': 0.4.1
|
||||||
'@types/cors': 2.8.17
|
'@types/cors': 2.8.17
|
||||||
'@types/node': 22.7.7
|
'@types/node': 22.7.8
|
||||||
accepts: 1.3.8
|
accepts: 1.3.8
|
||||||
base64id: 2.0.0
|
base64id: 2.0.0
|
||||||
cookie: 0.4.2
|
cookie: 0.4.2
|
||||||
|
@ -4022,7 +4022,7 @@ snapshots:
|
||||||
|
|
||||||
jest-worker@27.5.1:
|
jest-worker@27.5.1:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/node': 22.7.7
|
'@types/node': 22.7.8
|
||||||
merge-stream: 2.0.0
|
merge-stream: 2.0.0
|
||||||
supports-color: 8.1.1
|
supports-color: 8.1.1
|
||||||
|
|
||||||
|
|
220
rewriter/Cargo.lock
generated
220
rewriter/Cargo.lock
generated
|
@ -237,13 +237,14 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "compact_str"
|
name = "compact_str"
|
||||||
version = "0.7.1"
|
version = "0.8.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f86b9c4c00838774a6d902ef931eff7470720c51d90c2e32cfe15dc304737b3f"
|
checksum = "6050c3a16ddab2e412160b31f2c871015704239bca62f72f6e5f0be631d3f644"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"castaway",
|
"castaway",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"itoa",
|
"itoa",
|
||||||
|
"rustversion",
|
||||||
"ryu",
|
"ryu",
|
||||||
"serde",
|
"serde",
|
||||||
"static_assertions",
|
"static_assertions",
|
||||||
|
@ -259,6 +260,12 @@ dependencies = [
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cow-utils"
|
||||||
|
version = "0.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "417bef24afe1460300965a25ff4a24b8b45ad011948302ec221e8a0a81eb2c79"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-utils"
|
name = "crossbeam-utils"
|
||||||
version = "0.8.20"
|
version = "0.8.20"
|
||||||
|
@ -352,19 +359,6 @@ dependencies = [
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "gloo-utils"
|
|
||||||
version = "0.1.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "037fcb07216cb3a30f7292bd0176b050b7b9a052ba830ef7d5d65f6dc64ba58e"
|
|
||||||
dependencies = [
|
|
||||||
"js-sys",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"wasm-bindgen",
|
|
||||||
"web-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashbrown"
|
name = "hashbrown"
|
||||||
version = "0.14.5"
|
version = "0.14.5"
|
||||||
|
@ -519,6 +513,18 @@ dependencies = [
|
||||||
"hashbrown 0.15.0",
|
"hashbrown 0.15.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "instant"
|
||||||
|
version = "0.1.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"js-sys",
|
||||||
|
"wasm-bindgen",
|
||||||
|
"web-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "intrusive-collections"
|
name = "intrusive-collections"
|
||||||
version = "0.9.7"
|
version = "0.9.7"
|
||||||
|
@ -554,9 +560,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.159"
|
version = "0.2.161"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5"
|
checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "litemap"
|
name = "litemap"
|
||||||
|
@ -606,7 +612,7 @@ dependencies = [
|
||||||
"owo-colors",
|
"owo-colors",
|
||||||
"textwrap",
|
"textwrap",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"unicode-width",
|
"unicode-width 0.1.14",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -620,6 +626,12 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nonmax"
|
||||||
|
version = "0.5.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "610a5acd306ec67f907abe5567859a3c693fb9886eb1f012ab8f2a47bef3db51"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-bigint"
|
name = "num-bigint"
|
||||||
version = "0.4.6"
|
version = "0.4.6"
|
||||||
|
@ -705,9 +717,9 @@ checksum = "fb37767f6569cd834a413442455e0f066d0d522de8630436e2a1761d9726ba56"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "oxc_allocator"
|
name = "oxc_allocator"
|
||||||
version = "0.20.0"
|
version = "0.32.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d413f72d3253e9adff573635cfb5aca6f092aaee8b4252ee2d02b36fccc8fd2c"
|
checksum = "40baa80a3e4ae7cea94c1e04dc8820162b934f5f5cbca8a96e80a0b85a2815f4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"allocator-api2",
|
"allocator-api2",
|
||||||
"bumpalo",
|
"bumpalo",
|
||||||
|
@ -716,63 +728,92 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "oxc_ast"
|
name = "oxc_ast"
|
||||||
version = "0.20.0"
|
version = "0.32.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c90e5316ea1cdc09844cacbd9d11dfdaf80894c84d8917a8021903238dfcb449"
|
checksum = "d7eb50a1c3485609b4b2051bd23352c1e6a8743b9e345dd6def70b3470948429"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"num-bigint",
|
"num-bigint",
|
||||||
"oxc_allocator",
|
"oxc_allocator",
|
||||||
"oxc_ast_macros",
|
"oxc_ast_macros",
|
||||||
|
"oxc_estree",
|
||||||
|
"oxc_regular_expression",
|
||||||
"oxc_span",
|
"oxc_span",
|
||||||
"oxc_syntax",
|
"oxc_syntax",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tsify",
|
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "oxc_ast_macros"
|
name = "oxc_ast_macros"
|
||||||
version = "0.20.0"
|
version = "0.32.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e75a62baf313dede70692fe7b0dbb84bfdb8cddb118020067b924ee759b08a4e"
|
checksum = "0a4b29106d9f2bbcca4f5ee7a9325c99844ff9721d10103625cd5278795507fe"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "oxc_diagnostics"
|
|
||||||
version = "0.20.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e2963694eba6acab881fe014b843757b57f8bdb755f6014fb7f92790122bd57d"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"miette",
|
"proc-macro2",
|
||||||
"owo-colors",
|
"quote",
|
||||||
"textwrap",
|
"syn",
|
||||||
"unicode-width",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "oxc_index"
|
name = "oxc_diagnostics"
|
||||||
version = "0.20.0"
|
version = "0.32.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fbd279d0188e75bb7268c3d8f54a2b30837ea03135b739b90fb8360dd9f2add8"
|
checksum = "f2e7c7ff14a1a80cb229593d9fcfae6660c7b2cda8707caa4a89cb489656d156"
|
||||||
|
dependencies = [
|
||||||
|
"miette",
|
||||||
|
"owo-colors",
|
||||||
|
"rustc-hash",
|
||||||
|
"textwrap",
|
||||||
|
"unicode-width 0.2.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "oxc_ecmascript"
|
||||||
|
version = "0.32.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "17d5cf1710748afcda1269998d2003af79df1fef7c5b4183054aeb1b2a803ff6"
|
||||||
|
dependencies = [
|
||||||
|
"num-bigint",
|
||||||
|
"num-traits",
|
||||||
|
"oxc_ast",
|
||||||
|
"oxc_span",
|
||||||
|
"oxc_syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "oxc_estree"
|
||||||
|
version = "0.32.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "befa5f762524cdd768fee0321c4f19ee24e13e7340ca2a64629183a37875ba71"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "oxc_index"
|
||||||
|
version = "0.32.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "68a576b0f0a1ef9112504880a3ba82fa895c4cceb52cdc37825180c43b01336f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "oxc_parser"
|
name = "oxc_parser"
|
||||||
version = "0.20.0"
|
version = "0.32.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b7683a18fa64b8d7756b8a5630e84f075b4cd1dcf85adb04044055c33120e5f9"
|
checksum = "f43e722cd698a1ac383b645ddf6283757d4977b56f6dc278038b9ea74867a508"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"assert-unchecked",
|
"assert-unchecked",
|
||||||
"bitflags",
|
"bitflags",
|
||||||
|
"cow-utils",
|
||||||
"memchr",
|
"memchr",
|
||||||
"num-bigint",
|
"num-bigint",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"oxc_allocator",
|
"oxc_allocator",
|
||||||
"oxc_ast",
|
"oxc_ast",
|
||||||
"oxc_diagnostics",
|
"oxc_diagnostics",
|
||||||
|
"oxc_ecmascript",
|
||||||
|
"oxc_regular_expression",
|
||||||
"oxc_span",
|
"oxc_span",
|
||||||
"oxc_syntax",
|
"oxc_syntax",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
|
@ -780,34 +821,57 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "oxc_span"
|
name = "oxc_regular_expression"
|
||||||
version = "0.20.0"
|
version = "0.32.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "efafab0c8cfb6ac6da1b687fef84424d242437f4cfbed51ddfba8ac046ca4a93"
|
checksum = "231ed7fd6173c41270e019c4d1b2cd4bfa463a8abba32e0107bed6a7e9ceca93"
|
||||||
|
dependencies = [
|
||||||
|
"oxc_allocator",
|
||||||
|
"oxc_ast_macros",
|
||||||
|
"oxc_diagnostics",
|
||||||
|
"oxc_estree",
|
||||||
|
"oxc_span",
|
||||||
|
"phf",
|
||||||
|
"rustc-hash",
|
||||||
|
"serde",
|
||||||
|
"unicode-id-start",
|
||||||
|
"wasm-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "oxc_span"
|
||||||
|
version = "0.32.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "734602328c49aa8c31840e72662196ca1b0d7bf3585eca1f9ddbef127172112f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"compact_str",
|
"compact_str",
|
||||||
"miette",
|
"miette",
|
||||||
"oxc_allocator",
|
"oxc_allocator",
|
||||||
|
"oxc_ast_macros",
|
||||||
|
"oxc_estree",
|
||||||
"serde",
|
"serde",
|
||||||
"tsify",
|
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "oxc_syntax"
|
name = "oxc_syntax"
|
||||||
version = "0.20.0"
|
version = "0.32.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0ff2ce5c9adcdaee8dc28834ff7a4d9e33b0ecd9c9ec56a5066703cdd3426bb3"
|
checksum = "6a56d62a59f4ace25365c1d056d7ce3129ca3fb20e9337b19a0efe62d6bc84cb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"assert-unchecked",
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"dashmap 6.1.0",
|
"dashmap 6.1.0",
|
||||||
|
"nonmax",
|
||||||
|
"oxc_allocator",
|
||||||
|
"oxc_ast_macros",
|
||||||
|
"oxc_estree",
|
||||||
"oxc_index",
|
"oxc_index",
|
||||||
"oxc_span",
|
"oxc_span",
|
||||||
"phf",
|
"phf",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"ryu-js",
|
"ryu-js",
|
||||||
"serde",
|
"serde",
|
||||||
"tsify",
|
|
||||||
"unicode-id-start",
|
"unicode-id-start",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
@ -917,9 +981,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.87"
|
version = "1.0.88"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a"
|
checksum = "7c3a7fc5db1e57d5a779a352c8cdb57b29aa4c40cc69c3a68a7fedc815fbf2f9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
@ -989,10 +1053,12 @@ dependencies = [
|
||||||
"boa_engine",
|
"boa_engine",
|
||||||
"console_error_panic_hook",
|
"console_error_panic_hook",
|
||||||
"getrandom",
|
"getrandom",
|
||||||
|
"instant",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"obfstr",
|
"obfstr",
|
||||||
"oxc_allocator",
|
"oxc_allocator",
|
||||||
"oxc_ast",
|
"oxc_ast",
|
||||||
|
"oxc_diagnostics",
|
||||||
"oxc_parser",
|
"oxc_parser",
|
||||||
"oxc_span",
|
"oxc_span",
|
||||||
"oxc_syntax",
|
"oxc_syntax",
|
||||||
|
@ -1072,22 +1138,11 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serde_derive_internals"
|
|
||||||
version = "0.28.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e578a843d40b4189a4d66bba51d7684f57da5bd7c304c64e14bd63efbef49509"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.128"
|
version = "1.0.132"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8"
|
checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"memchr",
|
"memchr",
|
||||||
|
@ -1133,9 +1188,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.79"
|
version = "2.0.82"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590"
|
checksum = "83540f837a8afc019423a8edb95b52a8effe46957ee402287f4292fae35be021"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -1167,7 +1222,7 @@ checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"smawk",
|
"smawk",
|
||||||
"unicode-linebreak",
|
"unicode-linebreak",
|
||||||
"unicode-width",
|
"unicode-width 0.1.14",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1272,31 +1327,6 @@ dependencies = [
|
||||||
"winnow",
|
"winnow",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tsify"
|
|
||||||
version = "0.4.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d6b26cf145f2f3b9ff84e182c448eaf05468e247f148cf3d2a7d67d78ff023a0"
|
|
||||||
dependencies = [
|
|
||||||
"gloo-utils",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"tsify-macros",
|
|
||||||
"wasm-bindgen",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tsify-macros"
|
|
||||||
version = "0.4.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7a94b0f0954b3e59bfc2c246b4c8574390d94a4ad4ad246aaf2fb07d7dfd3b47"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"serde_derive_internals",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-bidi"
|
name = "unicode-bidi"
|
||||||
version = "0.3.17"
|
version = "0.3.17"
|
||||||
|
@ -1305,9 +1335,9 @@ checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-id-start"
|
name = "unicode-id-start"
|
||||||
version = "1.3.0"
|
version = "1.3.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "97e2a3c5fc9de285c0e805d98eba666adb4b2d9e1049ce44821ff7707cc34e91"
|
checksum = "2f322b60f6b9736017344fa0635d64be2f458fbc04eef65f6be22976dd1ffd5b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
|
@ -1336,6 +1366,12 @@ version = "0.1.14"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
|
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-width"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "url"
|
name = "url"
|
||||||
version = "2.5.2"
|
version = "2.5.2"
|
||||||
|
|
|
@ -25,13 +25,15 @@ panic = "abort"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
console_error_panic_hook = "0.1.7"
|
console_error_panic_hook = "0.1.7"
|
||||||
getrandom = { version = "0.2.15", features = ["js"] }
|
getrandom = { version = "0.2.15", features = ["js"] }
|
||||||
|
instant = { version = "0.1.13", features = ["wasm-bindgen"] }
|
||||||
js-sys = "0.3.69"
|
js-sys = "0.3.69"
|
||||||
obfstr = "0.4.3"
|
obfstr = "0.4.3"
|
||||||
oxc_allocator = "0.20.0"
|
oxc_allocator = "0.32.0"
|
||||||
oxc_ast = { version = "0.20.0", features = ["serialize"]}
|
oxc_ast = { version = "0.32.0", features = ["serialize"]}
|
||||||
oxc_parser = { version = "0.20.0" }
|
oxc_diagnostics = "0.32.0"
|
||||||
oxc_span = "0.20.0"
|
oxc_parser = "0.32.0"
|
||||||
oxc_syntax = "0.20.0"
|
oxc_span = "0.32.0"
|
||||||
|
oxc_syntax = "0.32.0"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
serde = "1.0.204"
|
serde = "1.0.204"
|
||||||
serde-wasm-bindgen = "0.6.5"
|
serde-wasm-bindgen = "0.6.5"
|
||||||
|
|
|
@ -9,6 +9,8 @@ pub enum RewriterError {
|
||||||
Url(#[from] url::ParseError),
|
Url(#[from] url::ParseError),
|
||||||
#[error("str fromutf8 error: {0}")]
|
#[error("str fromutf8 error: {0}")]
|
||||||
Str(#[from] std::str::Utf8Error),
|
Str(#[from] std::str::Utf8Error),
|
||||||
|
#[error("reflect set failed: {0}")]
|
||||||
|
ReflectSetFail(String),
|
||||||
|
|
||||||
#[error("{0} was not {1}")]
|
#[error("{0} was not {1}")]
|
||||||
Not(String, &'static str),
|
Not(String, &'static str),
|
||||||
|
|
|
@ -1,14 +1,27 @@
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod rewrite;
|
pub mod rewrite;
|
||||||
|
|
||||||
use std::{panic, str::FromStr};
|
use std::{panic, str::FromStr, sync::Arc, time::Duration};
|
||||||
|
|
||||||
use error::{Result, RewriterError};
|
use error::{Result, RewriterError};
|
||||||
|
use instant::Instant;
|
||||||
use js_sys::{Function, Object, Reflect};
|
use js_sys::{Function, Object, Reflect};
|
||||||
|
use oxc_diagnostics::{NamedSource, OxcDiagnostic};
|
||||||
use rewrite::{rewrite, Config, EncodeFn};
|
use rewrite::{rewrite, Config, EncodeFn};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
#[wasm_bindgen(typescript_custom_section)]
|
||||||
|
const REWRITER_OUTPUT: &'static str = r#"
|
||||||
|
type RewriterOutput = { js: Uint8Array, errors: string[], duration: bigint };
|
||||||
|
"#;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
extern "C" {
|
||||||
|
#[wasm_bindgen(typescript_type = "RewriterOutput")]
|
||||||
|
pub type RewriterOutput;
|
||||||
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#[wasm_bindgen(js_namespace = console)]
|
#[wasm_bindgen(js_namespace = console)]
|
||||||
|
@ -43,6 +56,14 @@ fn get_str(obj: &JsValue, k: &str) -> Result<String> {
|
||||||
.ok_or_else(|| RewriterError::not_str(k, obj))
|
.ok_or_else(|| RewriterError::not_str(k, obj))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_obj(obj: &Object, k: &str, v: &JsValue) -> Result<()> {
|
||||||
|
if !Reflect::set(&obj.into(), &k.into(), v)? {
|
||||||
|
Err(RewriterError::ReflectSetFail(k.to_string()))
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn get_flag(scramjet: &Object, url: &str, flag: &str) -> Result<bool> {
|
fn get_flag(scramjet: &Object, url: &str, flag: &str) -> Result<bool> {
|
||||||
let fenabled = get_obj(scramjet, "flagEnabled")?
|
let fenabled = get_obj(scramjet, "flagEnabled")?
|
||||||
.dyn_into::<Function>()
|
.dyn_into::<Function>()
|
||||||
|
@ -90,25 +111,68 @@ fn drmcheck() -> bool {
|
||||||
return vec![obfstr!("http://localhost:1337")].contains(&true_origin.as_str());
|
return vec![obfstr!("http://localhost:1337")].contains(&true_origin.as_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn duration_to_millis_f64(duration: Duration) -> f64 {
|
||||||
|
(duration.as_secs() as f64) * 1_000f64 + (duration.subsec_nanos() as f64) / 1_000_000f64
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_rewriter_output(
|
||||||
|
out: (Vec<u8>, Vec<OxcDiagnostic>),
|
||||||
|
url: String,
|
||||||
|
src: String,
|
||||||
|
duration: Duration,
|
||||||
|
) -> Result<RewriterOutput> {
|
||||||
|
let src = Arc::new(NamedSource::new(url, src).with_language("javascript"));
|
||||||
|
let errs: Vec<_> = out
|
||||||
|
.1
|
||||||
|
.into_iter()
|
||||||
|
.map(|x| format!("{:?}", x.with_source_code(src.clone())))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let obj = Object::new();
|
||||||
|
set_obj(&obj, "js", &out.0.into())?;
|
||||||
|
set_obj(&obj, "errors", &errs.into())?;
|
||||||
|
set_obj(&obj, "duration", &duration_to_millis_f64(duration).into())?;
|
||||||
|
|
||||||
|
Ok(RewriterOutput::from(JsValue::from(obj)))
|
||||||
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn rewrite_js(js: &str, url: &str, scramjet: &Object) -> Result<Vec<u8>> {
|
pub fn rewrite_js(
|
||||||
|
js: String,
|
||||||
|
url: &str,
|
||||||
|
script_url: String,
|
||||||
|
scramjet: &Object,
|
||||||
|
) -> Result<RewriterOutput> {
|
||||||
#[cfg(feature = "drm")]
|
#[cfg(feature = "drm")]
|
||||||
if !drmcheck() {
|
if !drmcheck() {
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
rewrite(js, Url::from_str(url)?, get_config(scramjet, url)?)
|
let before = Instant::now();
|
||||||
|
let out = rewrite(&js, Url::from_str(url)?, get_config(scramjet, url)?)?;
|
||||||
|
let after = Instant::now();
|
||||||
|
|
||||||
|
create_rewriter_output(out, script_url, js, after - before)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn rewrite_js_from_arraybuffer(js: &[u8], url: &str, scramjet: &Object) -> Result<Vec<u8>> {
|
pub fn rewrite_js_from_arraybuffer(
|
||||||
|
js: Vec<u8>,
|
||||||
|
url: &str,
|
||||||
|
script_url: String,
|
||||||
|
scramjet: &Object,
|
||||||
|
) -> Result<RewriterOutput> {
|
||||||
#[cfg(feature = "drm")]
|
#[cfg(feature = "drm")]
|
||||||
if !drmcheck() {
|
if !drmcheck() {
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
// we know that this is a valid utf-8 string
|
// we know that this is a valid utf-8 string
|
||||||
let js = unsafe { std::str::from_utf8_unchecked(js) };
|
let js = unsafe { String::from_utf8_unchecked(js) };
|
||||||
|
|
||||||
rewrite(js, Url::from_str(url)?, get_config(scramjet, url)?)
|
let before = Instant::now();
|
||||||
|
let out = rewrite(&js, Url::from_str(url)?, get_config(scramjet, url)?)?;
|
||||||
|
let after = Instant::now();
|
||||||
|
|
||||||
|
create_rewriter_output(out, script_url, js, after - before)
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,6 +130,7 @@ fn dorewrite(source_text: &str) -> Result<String> {
|
||||||
strict_rewrites: true,
|
strict_rewrites: true,
|
||||||
},
|
},
|
||||||
)?
|
)?
|
||||||
|
.0
|
||||||
.as_slice(),
|
.as_slice(),
|
||||||
)?
|
)?
|
||||||
.to_string())
|
.to_string())
|
||||||
|
|
|
@ -9,8 +9,9 @@ use oxc_ast::{
|
||||||
visit::walk,
|
visit::walk,
|
||||||
Visit,
|
Visit,
|
||||||
};
|
};
|
||||||
|
use oxc_diagnostics::OxcDiagnostic;
|
||||||
use oxc_parser::Parser;
|
use oxc_parser::Parser;
|
||||||
use oxc_span::{Atom, SourceType, Span};
|
use oxc_span::{Atom, GetSpan, SourceType, Span};
|
||||||
use oxc_syntax::operator::{AssignmentOperator, UnaryOperator};
|
use oxc_syntax::operator::{AssignmentOperator, UnaryOperator};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -148,7 +149,7 @@ impl<'a> Visit<'a> for Rewriter {
|
||||||
&& !matches!(s.object, Expression::MetaProperty(_))
|
&& !matches!(s.object, Expression::MetaProperty(_))
|
||||||
&& !matches!(s.object, Expression::Super(_))
|
&& !matches!(s.object, Expression::Super(_))
|
||||||
{
|
{
|
||||||
let span = expression_span(&s.object);
|
let span = s.object.span();
|
||||||
self.jschanges.push(JsChange::GenericChange {
|
self.jschanges.push(JsChange::GenericChange {
|
||||||
span: Span::new(span.start, span.start),
|
span: Span::new(span.start, span.start),
|
||||||
text: " $scramitize(".to_string(),
|
text: " $scramitize(".to_string(),
|
||||||
|
@ -359,7 +360,7 @@ impl<'a> Visit<'a> for Rewriter {
|
||||||
self.jschanges.push(JsChange::Assignment {
|
self.jschanges.push(JsChange::Assignment {
|
||||||
name: s.name.to_string(),
|
name: s.name.to_string(),
|
||||||
entirespan: it.span,
|
entirespan: it.span,
|
||||||
rhsspan: expression_span(&it.right),
|
rhsspan: it.right.span(),
|
||||||
op: it.operator,
|
op: it.operator,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -383,55 +384,6 @@ impl<'a> Visit<'a> for Rewriter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expression_span(e: &Expression) -> Span {
|
|
||||||
// enums.split("\n").filter(f=>f).map(p=>p.trimLeft()).filter(p=>!p.startsWith("#")).map(p=>p.replace(/\(.*/,"")).map(p=>`E::${p}(s) => s.span`).join(",\n")
|
|
||||||
use Expression as E;
|
|
||||||
match e {
|
|
||||||
E::BooleanLiteral(s) => s.span,
|
|
||||||
E::NullLiteral(s) => s.span,
|
|
||||||
E::NumericLiteral(s) => s.span,
|
|
||||||
E::BigIntLiteral(s) => s.span,
|
|
||||||
E::RegExpLiteral(s) => s.span,
|
|
||||||
E::StringLiteral(s) => s.span,
|
|
||||||
E::TemplateLiteral(s) => s.span,
|
|
||||||
E::Identifier(s) => s.span,
|
|
||||||
E::MetaProperty(s) => s.span,
|
|
||||||
E::Super(s) => s.span,
|
|
||||||
E::ArrayExpression(s) => s.span,
|
|
||||||
E::ArrowFunctionExpression(s) => s.span,
|
|
||||||
E::AssignmentExpression(s) => s.span,
|
|
||||||
E::AwaitExpression(s) => s.span,
|
|
||||||
E::BinaryExpression(s) => s.span,
|
|
||||||
E::CallExpression(s) => s.span,
|
|
||||||
E::ChainExpression(s) => s.span,
|
|
||||||
E::ClassExpression(s) => s.span,
|
|
||||||
E::ConditionalExpression(s) => s.span,
|
|
||||||
E::FunctionExpression(s) => s.span,
|
|
||||||
E::ImportExpression(s) => s.span,
|
|
||||||
E::LogicalExpression(s) => s.span,
|
|
||||||
E::NewExpression(s) => s.span,
|
|
||||||
E::ObjectExpression(s) => s.span,
|
|
||||||
E::ParenthesizedExpression(s) => s.span,
|
|
||||||
E::SequenceExpression(s) => s.span,
|
|
||||||
E::TaggedTemplateExpression(s) => s.span,
|
|
||||||
E::ThisExpression(s) => s.span,
|
|
||||||
E::UnaryExpression(s) => s.span,
|
|
||||||
E::UpdateExpression(s) => s.span,
|
|
||||||
E::YieldExpression(s) => s.span,
|
|
||||||
E::PrivateInExpression(s) => s.span,
|
|
||||||
E::JSXElement(s) => s.span,
|
|
||||||
E::JSXFragment(s) => s.span,
|
|
||||||
E::TSAsExpression(s) => s.span,
|
|
||||||
E::TSSatisfiesExpression(s) => s.span,
|
|
||||||
E::TSTypeAssertion(s) => s.span,
|
|
||||||
E::TSNonNullExpression(s) => s.span,
|
|
||||||
E::TSInstantiationExpression(s) => s.span,
|
|
||||||
E::ComputedMemberExpression(s) => s.span,
|
|
||||||
E::StaticMemberExpression(s) => s.span,
|
|
||||||
E::PrivateFieldExpression(s) => s.span,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// js MUST not be able to get a reference to any of these because sbx
|
// js MUST not be able to get a reference to any of these because sbx
|
||||||
const UNSAFE_GLOBALS: &[&str] = &[
|
const UNSAFE_GLOBALS: &[&str] = &[
|
||||||
"window",
|
"window",
|
||||||
|
@ -459,19 +411,11 @@ fn random_string() -> String {
|
||||||
.to_string()
|
.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rewrite(js: &str, url: Url, config: Config) -> Result<Vec<u8>> {
|
pub fn rewrite(js: &str, url: Url, config: Config) -> Result<(Vec<u8>, Vec<OxcDiagnostic>)> {
|
||||||
let allocator = Allocator::default();
|
let allocator = Allocator::default();
|
||||||
let source_type = SourceType::default();
|
let source_type = SourceType::default();
|
||||||
let ret = Parser::new(&allocator, js, source_type).parse();
|
let ret = Parser::new(&allocator, js, source_type).parse();
|
||||||
|
|
||||||
for err in ret.errors {
|
|
||||||
let cloned = js.to_string();
|
|
||||||
let err = err.with_source_code(cloned);
|
|
||||||
println!("oxc parse error {err:?}");
|
|
||||||
#[cfg(target_family = "wasm")]
|
|
||||||
crate::error(&format!("oxc parse error {err:?}"))
|
|
||||||
}
|
|
||||||
|
|
||||||
let program = ret.program;
|
let program = ret.program;
|
||||||
|
|
||||||
let sourcetag = random_string();
|
let sourcetag = random_string();
|
||||||
|
@ -575,9 +519,9 @@ pub fn rewrite(js: &str, url: Url, config: Config) -> Result<Vec<u8>> {
|
||||||
format!(
|
format!(
|
||||||
"((t)=>$scramjet$tryset({},\"{}\",t)||({}{}t))({})",
|
"((t)=>$scramjet$tryset({},\"{}\",t)||({}{}t))({})",
|
||||||
name,
|
name,
|
||||||
fmt_op(*op),
|
op.as_str(),
|
||||||
name,
|
name,
|
||||||
fmt_op(*op),
|
op.as_str(),
|
||||||
&js[rhsspan.start as usize..rhsspan.end as usize]
|
&js[rhsspan.start as usize..rhsspan.end as usize]
|
||||||
)
|
)
|
||||||
.as_bytes(),
|
.as_bytes(),
|
||||||
|
@ -607,10 +551,10 @@ pub fn rewrite(js: &str, url: Url, config: Config) -> Result<Vec<u8>> {
|
||||||
|
|
||||||
sourcemap.extend_from_slice(&buffer);
|
sourcemap.extend_from_slice(&buffer);
|
||||||
|
|
||||||
return Ok(sourcemap);
|
return Ok((sourcemap, ret.errors));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(buffer)
|
Ok((buffer, ret.errors))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn json_escape_string(s: &str) -> String {
|
fn json_escape_string(s: &str) -> String {
|
||||||
|
@ -629,24 +573,3 @@ fn json_escape_string(s: &str) -> String {
|
||||||
}
|
}
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_op(op: AssignmentOperator) -> &'static str {
|
|
||||||
match op {
|
|
||||||
AssignmentOperator::Assign => "=",
|
|
||||||
AssignmentOperator::Addition => "+=",
|
|
||||||
AssignmentOperator::Subtraction => "-=",
|
|
||||||
AssignmentOperator::Multiplication => "*=",
|
|
||||||
AssignmentOperator::Division => "/=",
|
|
||||||
AssignmentOperator::Remainder => "%=",
|
|
||||||
AssignmentOperator::Exponential => "**=",
|
|
||||||
AssignmentOperator::ShiftLeft => "<<=",
|
|
||||||
AssignmentOperator::ShiftRight => ">>=",
|
|
||||||
AssignmentOperator::ShiftRightZeroFill => ">>>=",
|
|
||||||
AssignmentOperator::BitwiseAnd => "&=",
|
|
||||||
AssignmentOperator::BitwiseXOR => "^=",
|
|
||||||
AssignmentOperator::BitwiseOR => "|=",
|
|
||||||
AssignmentOperator::LogicalAnd => "&&=",
|
|
||||||
AssignmentOperator::LogicalOr => "||=",
|
|
||||||
AssignmentOperator::LogicalNullish => "??=",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import {
|
||||||
unrewriteUrl,
|
unrewriteUrl,
|
||||||
rewriteUrl,
|
rewriteUrl,
|
||||||
} from "../shared";
|
} from "../shared";
|
||||||
import { BareClient as BareClientType } from "@mercuryworkshop/bare-mux";
|
import type { BareClient as BareClientType } from "@mercuryworkshop/bare-mux";
|
||||||
import { createWrapFn } from "./shared/wrap";
|
import { createWrapFn } from "./shared/wrap";
|
||||||
import { NavigateEvent } from "./events";
|
import { NavigateEvent } from "./events";
|
||||||
import type { URLMeta } from "../shared/rewriters/url";
|
import type { URLMeta } from "../shared/rewriters/url";
|
||||||
|
@ -328,7 +328,7 @@ export class ScramjetClient {
|
||||||
if ((err.stack as any) instanceof Object) {
|
if ((err.stack as any) instanceof Object) {
|
||||||
//@ts-expect-error i'm not going to explain this
|
//@ts-expect-error i'm not going to explain this
|
||||||
err.stack = err.stack.stack;
|
err.stack = err.stack.stack;
|
||||||
console.error("ERROR FROM SCRMAJET INTERNALS", err);
|
console.error("ERROR FROM SCRAMJET INTERNALS", err);
|
||||||
} else {
|
} else {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { rewriteUrl } from "../../shared";
|
||||||
import { UrlChangeEvent } from "../events";
|
import { UrlChangeEvent } from "../events";
|
||||||
|
|
||||||
export default function (client: ScramjetClient, self: typeof globalThis) {
|
export default function (client: ScramjetClient, self: typeof globalThis) {
|
||||||
client.Proxy("history.pushState", {
|
client.Proxy("History.prototype.pushState", {
|
||||||
apply(ctx) {
|
apply(ctx) {
|
||||||
if (ctx.args[2]) ctx.args[2] = rewriteUrl(ctx.args[2], client.meta);
|
if (ctx.args[2]) ctx.args[2] = rewriteUrl(ctx.args[2], client.meta);
|
||||||
ctx.call();
|
ctx.call();
|
||||||
|
@ -13,7 +13,7 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
client.Proxy("history.replaceState", {
|
client.Proxy("History.prototype.replaceState", {
|
||||||
apply(ctx) {
|
apply(ctx) {
|
||||||
if (ctx.args[2]) ctx.args[2] = rewriteUrl(ctx.args[2], client.meta);
|
if (ctx.args[2]) ctx.args[2] = rewriteUrl(ctx.args[2], client.meta);
|
||||||
ctx.call();
|
ctx.call();
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { rewriteUrl } from "../../../shared";
|
||||||
import { ScramjetClient } from "../../client";
|
import { ScramjetClient } from "../../client";
|
||||||
|
|
||||||
export default function (client: ScramjetClient, self) {
|
export default function (client: ScramjetClient, self) {
|
||||||
client.Proxy("navigator.sendBeacon", {
|
client.Proxy("Navigator.prototype.sendBeacon", {
|
||||||
apply(ctx) {
|
apply(ctx) {
|
||||||
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
|
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
|
||||||
},
|
},
|
||||||
|
|
|
@ -16,12 +16,6 @@ export default function (client: ScramjetClient, _self: typeof globalThis) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// client.Proxy("Headers", {
|
|
||||||
// construct(ctx) {
|
|
||||||
// ctx.args[0] = rewriteHeaders(ctx.args[0]);
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
|
|
||||||
client.Proxy("Request", {
|
client.Proxy("Request", {
|
||||||
construct(ctx) {
|
construct(ctx) {
|
||||||
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
|
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
|
||||||
|
@ -43,10 +37,4 @@ export default function (client: ScramjetClient, _self: typeof globalThis) {
|
||||||
return unrewriteUrl(ctx.get() as string);
|
return unrewriteUrl(ctx.get() as string);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// client.Proxy("Response.redirect", {
|
|
||||||
// apply(ctx) {
|
|
||||||
// ctx.args[0] = encodeUrl(ctx.args[0]);
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ export function createWrapFn(client: ScramjetClient, self: typeof globalThis) {
|
||||||
return function (identifier: any) {
|
return function (identifier: any) {
|
||||||
if (identifier === self) return client.globalProxy;
|
if (identifier === self) return client.globalProxy;
|
||||||
if (identifier === self.location) return client.locationProxy;
|
if (identifier === self.location) return client.locationProxy;
|
||||||
if (identifier === eval) return indirectEval;
|
if (identifier === eval) return indirectEval.bind(client);
|
||||||
|
|
||||||
if (iswindow) {
|
if (iswindow) {
|
||||||
if (identifier === self.parent) {
|
if (identifier === self.parent) {
|
||||||
|
@ -22,9 +22,23 @@ export function createWrapFn(client: ScramjetClient, self: typeof globalThis) {
|
||||||
}
|
}
|
||||||
} else if (identifier === self.document) {
|
} else if (identifier === self.document) {
|
||||||
return client.documentProxy;
|
return client.documentProxy;
|
||||||
|
} else if (identifier === self.top) {
|
||||||
|
// instead of returning top, we need to return the uppermost parent that's inside a scramjet context
|
||||||
|
let current = self.self;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
const test = current.parent.self;
|
||||||
|
if (test === current) break; // there is no parent, actual or emulated.
|
||||||
|
|
||||||
|
// ... then `test` represents a window outside of the proxy context, and therefore `current` is the topmost window in the proxy context
|
||||||
|
if (!(SCRAMJETCLIENT in test)) break;
|
||||||
|
|
||||||
|
// test is also insde a proxy, so we should continue up the chain
|
||||||
|
current = test;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO .top
|
return current[SCRAMJETCLIENT].globalProxy.window;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return identifier;
|
return identifier;
|
||||||
|
@ -44,6 +58,7 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
|
||||||
Object.defineProperty(self, config.globals.wrapthisfn, {
|
Object.defineProperty(self, config.globals.wrapthisfn, {
|
||||||
value: function (i) {
|
value: function (i) {
|
||||||
if (i === self) return client.globalProxy;
|
if (i === self) return client.globalProxy;
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
},
|
},
|
||||||
writable: false,
|
writable: false,
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {
|
||||||
initSync,
|
initSync,
|
||||||
rewrite_js,
|
rewrite_js,
|
||||||
rewrite_js_from_arraybuffer,
|
rewrite_js_from_arraybuffer,
|
||||||
|
RewriterOutput,
|
||||||
} from "../../../rewriter/out/rewriter.js";
|
} from "../../../rewriter/out/rewriter.js";
|
||||||
import { $scramjet, flagEnabled } from "../../scramjet";
|
import { $scramjet, flagEnabled } from "../../scramjet";
|
||||||
|
|
||||||
|
@ -19,6 +20,53 @@ init();
|
||||||
|
|
||||||
Error.stackTraceLimit = 50;
|
Error.stackTraceLimit = 50;
|
||||||
|
|
||||||
|
const decoder = new TextDecoder();
|
||||||
|
|
||||||
|
function rewriteJsWrapper(
|
||||||
|
input: string | ArrayBuffer,
|
||||||
|
meta: URLMeta
|
||||||
|
): string | ArrayBuffer {
|
||||||
|
let out: RewriterOutput;
|
||||||
|
if (typeof input === "string") {
|
||||||
|
out = rewrite_js(
|
||||||
|
input,
|
||||||
|
meta.base.href,
|
||||||
|
"PERCS_PLEASE_FILL_THIS_IN.js",
|
||||||
|
$scramjet
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
out = rewrite_js_from_arraybuffer(
|
||||||
|
new Uint8Array(input),
|
||||||
|
meta.base.href,
|
||||||
|
"PERCS_PLEASE_FILL_THIS_IN.js",
|
||||||
|
$scramjet
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const { js, errors, duration } = out;
|
||||||
|
|
||||||
|
// TODO: maybe make this a scram flag?
|
||||||
|
if (true) {
|
||||||
|
for (const error of errors) {
|
||||||
|
console.error("oxc parse error", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: maybe make this a scram flag?
|
||||||
|
if (true) {
|
||||||
|
let timespan: string;
|
||||||
|
if (duration < 1n) {
|
||||||
|
timespan = "BLAZINGLY FAST";
|
||||||
|
} else if (duration < 500n) {
|
||||||
|
timespan = "decent speed";
|
||||||
|
} else {
|
||||||
|
timespan = "really slow";
|
||||||
|
}
|
||||||
|
console.log(`oxc rewrite was ${timespan} (${duration}ms)`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return typeof input === "string" ? decoder.decode(js) : js;
|
||||||
|
}
|
||||||
|
|
||||||
export function rewriteJs(js: string | ArrayBuffer, meta: URLMeta) {
|
export function rewriteJs(js: string | ArrayBuffer, meta: URLMeta) {
|
||||||
if (flagEnabled("naiiveRewriter", meta.origin)) {
|
if (flagEnabled("naiiveRewriter", meta.origin)) {
|
||||||
const text = typeof js === "string" ? js : new TextDecoder().decode(js);
|
const text = typeof js === "string" ? js : new TextDecoder().decode(js);
|
||||||
|
@ -28,19 +76,7 @@ export function rewriteJs(js: string | ArrayBuffer, meta: URLMeta) {
|
||||||
return rewriteJsNaiive(text);
|
return rewriteJsNaiive(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
// const before = performance.now();
|
js = rewriteJsWrapper(js, meta);
|
||||||
if (typeof js === "string") {
|
|
||||||
js = new TextDecoder().decode(rewrite_js(js, meta.base.href, $scramjet));
|
|
||||||
} else {
|
|
||||||
js = rewrite_js_from_arraybuffer(
|
|
||||||
new Uint8Array(js),
|
|
||||||
meta.base.href,
|
|
||||||
$scramjet
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// const after = performance.now();
|
|
||||||
|
|
||||||
// dbg.debug("Rewrite took", Math.floor((after - before) * 10) / 10, "ms");
|
|
||||||
|
|
||||||
return js;
|
return js;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,11 @@
|
||||||
|
// dumb hack to allow firefox to work (please dont do this in prod)
|
||||||
|
if (navigator.userAgent.includes("Firefox")) {
|
||||||
|
Object.defineProperty(globalThis, "crossOriginIsolated", {
|
||||||
|
value: true,
|
||||||
|
writable: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
importScripts(
|
importScripts(
|
||||||
"/scram/scramjet.wasm.js",
|
"/scram/scramjet.wasm.js",
|
||||||
"/scram/scramjet.shared.js",
|
"/scram/scramjet.shared.js",
|
||||||
|
|
17
tests/util/inspectConsole.ts
Normal file
17
tests/util/inspectConsole.ts
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import { Page } from "@playwright/test";
|
||||||
|
|
||||||
|
export function registerInspect(page: Page) {
|
||||||
|
let hasOxcError = false;
|
||||||
|
let hasScramjetError = false;
|
||||||
|
page.on("console", async (msg) => {
|
||||||
|
if (msg.type() === "error") {
|
||||||
|
if (msg.text().includes("oxc parse error") && !hasOxcError) {
|
||||||
|
hasOxcError = true;
|
||||||
|
console.log("OXC parse error detected! Please review manually.")
|
||||||
|
} else if (msg.text().includes("ERROR FROM SCRAMJET INTERNALS") && !hasScramjetError) {
|
||||||
|
hasScramjetError = true;
|
||||||
|
console.log("Scramjet error detected! Please review manually.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
|
@ -1,8 +1,11 @@
|
||||||
/* eslint-disable no-async-promise-executor */
|
/* eslint-disable no-async-promise-executor */
|
||||||
import { expect, FrameLocator, Page } from "@playwright/test";
|
import { expect, FrameLocator, Page } from "@playwright/test";
|
||||||
|
import { registerInspect } from "./inspectConsole";
|
||||||
|
|
||||||
export function setupPage(page: Page, url: string): Promise<FrameLocator> {
|
export function setupPage(page: Page, url: string): Promise<FrameLocator> {
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
|
// Hack to disable HTTP cache.
|
||||||
|
await page.route("**", route => route.continue());
|
||||||
// Goto base url defined in config.
|
// Goto base url defined in config.
|
||||||
await page.goto("/");
|
await page.goto("/");
|
||||||
await page.waitForSelector(".version > b");
|
await page.waitForSelector(".version > b");
|
||||||
|
@ -18,6 +21,9 @@ export function setupPage(page: Page, url: string): Promise<FrameLocator> {
|
||||||
await page.waitForTimeout(1000);
|
await page.waitForTimeout(1000);
|
||||||
|
|
||||||
await bar.press("Enter");
|
await bar.press("Enter");
|
||||||
|
|
||||||
|
registerInspect(page);
|
||||||
|
|
||||||
resolve(frame);
|
resolve(frame);
|
||||||
});
|
});
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue