Skip to content

The headless browser for AI agents and web scraping

fix(release): shrink binaries and expose plugin interfaces

SGavrld6c9ef537cdf
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 53fbc6dd..dec642e8 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -77,12 +77,12 @@ jobs:
"LIBCLANG_PATH=C:\Program Files\LLVM\bin" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Build no-render release binary
- run: cargo build --release --target ${{ matrix.target }} -p obscura-cli --bins --no-default-features
+ run: cargo build --profile release-dist --target ${{ matrix.target }} -p obscura-cli --bins --no-default-features
- name: Stage no-render release binary
shell: bash
run: |
- BIN_DIR=target/${{ matrix.target }}/release
+ BIN_DIR=target/${{ matrix.target }}/release-dist
mkdir -p dist/no-render
if [ -f "$BIN_DIR/obscura.exe" ]; then
cp "$BIN_DIR/obscura.exe" "$BIN_DIR/obscura-worker.exe" dist/no-render/
@@ -91,12 +91,12 @@ jobs:
fi
- name: Build no-render stealth release binary
- run: cargo build --release --target ${{ matrix.target }} -p obscura-cli --bins --no-default-features --features stealth
+ run: cargo build --profile release-dist --target ${{ matrix.target }} -p obscura-cli --bins --no-default-features --features stealth
- name: Stage no-render stealth release binary
shell: bash
run: |
- BIN_DIR=target/${{ matrix.target }}/release
+ BIN_DIR=target/${{ matrix.target }}/release-dist
mkdir -p dist/no-render-stealth
if [ -f "$BIN_DIR/obscura.exe" ]; then
cp "$BIN_DIR/obscura.exe" "$BIN_DIR/obscura-worker.exe" dist/no-render-stealth/
@@ -105,12 +105,12 @@ jobs:
fi
- name: Build render-enabled release binary
- run: cargo build --release --target ${{ matrix.target }} -p obscura-cli --bins --features render
+ run: cargo build --profile release-dist --target ${{ matrix.target }} -p obscura-cli --bins --features render
- name: Stage default release binary
shell: bash
run: |
- BIN_DIR=target/${{ matrix.target }}/release
+ BIN_DIR=target/${{ matrix.target }}/release-dist
mkdir -p dist/default
if [ -f "$BIN_DIR/obscura.exe" ]; then
cp "$BIN_DIR/obscura.exe" "$BIN_DIR/obscura-worker.exe" dist/default/
@@ -119,12 +119,12 @@ jobs:
fi
- name: Build render-enabled stealth release binary
- run: cargo build --release --target ${{ matrix.target }} -p obscura-cli --bins --features render,stealth
+ run: cargo build --profile release-dist --target ${{ matrix.target }} -p obscura-cli --bins --features render,stealth
- name: Stage stealth release binary
shell: bash
run: |
- BIN_DIR=target/${{ matrix.target }}/release
+ BIN_DIR=target/${{ matrix.target }}/release-dist
mkdir -p dist/stealth
if [ -f "$BIN_DIR/obscura.exe" ]; then
cp "$BIN_DIR/obscura.exe" "$BIN_DIR/obscura-worker.exe" dist/stealth/
diff --git a/Cargo.toml b/Cargo.toml
index bfa6a136..8efd2a66 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -69,3 +69,10 @@ cosmic-text = { path = "vendor/cosmic-text" }
# would turn every catchable op panic into a hard crash.
[profile.release]
panic = "unwind"
+
+[profile.release-dist]
+inherits = "release"
+opt-level = "s"
+lto = "fat"
+codegen-units = 1
+strip = "symbols"
diff --git a/README.md b/README.md
index ee902d22..b6d0f09b 100644
--- a/README.md
+++ b/README.md
@@ -30,7 +30,7 @@ Obscura is a headless browser engine written in Rust, built for web scraping and
| Metric | Obscura | Headless Chrome |
|--------------|--------------|------------------|
| Memory | **30 MB** | 200+ MB |
-| Binary size | **70 MB** | 300+ MB |
+| Binary size | **~70 MiB** | 300+ MB |
| Anti-detect | **Built-in** | None |
| Page load | **85 ms** | ~500 ms |
| Startup | **Instant** | ~2s |
diff --git a/crates/obscura-js/js/bootstrap.js b/crates/obscura-js/js/bootstrap.js
index 877853b9..814a0566 100644
--- a/crates/obscura-js/js/bootstrap.js
+++ b/crates/obscura-js/js/bootstrap.js
@@ -52,6 +52,7 @@
// Pre-declaring them non-enumerable here is enough -- per the note above,
// the later `globalThis.X = X` assignments only update the value.
'Node', 'Element', 'Document', 'DocumentFragment', 'DocumentType',
+ 'Navigator', 'PluginArray', 'Plugin', 'MimeType', 'MimeTypeArray',
'Animation', 'KeyframeEffect', 'DocumentTimeline',
'Text', 'Comment', 'CDATASection', 'ProcessingInstruction', 'CharacterData',
'CSSStyleDeclaration', 'DOMStringMap', 'DOMTokenList', 'NamedNodeMap', 'Screen', 'NetworkInformation',
@@ -6778,6 +6779,12 @@ _markNative(MimeTypeArray);
_markNative(MimeTypeArray.prototype.item);
_markNative(MimeTypeArray.prototype.namedItem);
+globalThis.Navigator = Navigator;
+globalThis.PluginArray = PluginArray;
+globalThis.Plugin = Plugin;
+globalThis.MimeType = MimeType;
+globalThis.MimeTypeArray = MimeTypeArray;
+
class NetworkInformation {
constructor() { this._listeners = Object.create(null); }
get downlink() { return 10; }
diff --git a/crates/obscura-js/src/runtime.rs b/crates/obscura-js/src/runtime.rs
index e2821525..66233933 100644
--- a/crates/obscura-js/src/runtime.rs
+++ b/crates/obscura-js/src/runtime.rs
@@ -15548,6 +15548,26 @@ mod tests {
assert_eq!(wd, serde_json::json!(false));
let plugins = rt.evaluate("navigator.plugins.length").unwrap();
assert!(plugins.as_f64().unwrap() > 0.0, "Should have plugins");
+ let plugin_interfaces = rt
+ .evaluate(
+ r#"({
+ Navigator: typeof Navigator,
+ PluginArray: typeof PluginArray,
+ Plugin: typeof Plugin,
+ MimeType: typeof MimeType,
+ MimeTypeArray: typeof MimeTypeArray,
+ pluginsMatch: navigator.plugins instanceof PluginArray,
+ enumerable: Object.getOwnPropertyDescriptor(window, "PluginArray").enumerable,
+ })"#,
+ )
+ .unwrap();
+ assert_eq!(plugin_interfaces["Navigator"], "function");
+ assert_eq!(plugin_interfaces["PluginArray"], "function");
+ assert_eq!(plugin_interfaces["Plugin"], "function");
+ assert_eq!(plugin_interfaces["MimeType"], "function");
+ assert_eq!(plugin_interfaces["MimeTypeArray"], "function");
+ assert_eq!(plugin_interfaces["pluginsMatch"], true);
+ assert_eq!(plugin_interfaces["enumerable"], false);
let chrome = rt.evaluate("typeof window.chrome").unwrap();
assert_eq!(chrome, serde_json::json!("object"));
}
diff --git a/docs/README.md b/docs/README.md
index 1ce73e70..92035cd0 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -5,7 +5,7 @@ Obscura is an open-source headless browser engine written in Rust. It runs JavaS
| Metric | Obscura | Headless Chrome |
| ----------- | -------- | --------------- |
| Memory | 30 MB | 200+ MB |
-| Binary size | 70 MB | 300+ MB |
+| Binary size | ~70 MiB | 300+ MB |
| Startup | Instant | ~2s |
| Page load | 85 ms | ~500 ms |
| Anti-detect | Built-in | None |