Skip to content

feat: Add WebAssembly (WASM) compiler target and browser CDN support - #69

Open
devgabrielmarcondes wants to merge 2 commits into
firecrawl:mainfrom
devgabrielmarcondes:feature/wasm-support
Open

feat: Add WebAssembly (WASM) compiler target and browser CDN support#69
devgabrielmarcondes wants to merge 2 commits into
firecrawl:mainfrom
devgabrielmarcondes:feature/wasm-support

Conversation

@devgabrielmarcondes

Copy link
Copy Markdown

This PR introduces the foundation for adapting pdf-inspector to run fully client-side on browsers via WebAssembly (WASM).

Changes:

  • Conditionally disabled the rayon threading dependency strictly for wasm32 environments (as WebAssembly forbids multi-threading/OS threads by default).
  • Implemented a mocked CompatInstant fallback using js_sys::Date::now() to resolve the RuntimeError: unreachable fatal error occurring during WASM compilation from std::time::Instant::now().
  • Explicitly enabled the wasm_js feature for the getrandom crate exclusively for cfg(target_arch = "wasm32").
  • Exported the core process_pdf_mem logic through the wasm-bindgen API in a new src/wasm.rs module.
  • Added a full demo client wasm-demo/index.html showcasing the direct conversion happening purely client-side without OCR delays.

Demo (WASM running pure client-side processing)

firecrawl-wasm-ezgif com-video-to-gif-converter

@abimaelmartell

Copy link
Copy Markdown
Member

Hi, this is very impressive, thanks for the contribution!

I can't review your code because your first commit changed every file here. I suspect your code editor might have modified line endings or something else. Can you clean it up so i can review it?

Thanks,

Best,
Abimael Martell

@devgabrielmarcondes

Copy link
Copy Markdown
Author

Hi Abimael,

Sorry about that! My Windows Git automatically checked out CRLF line endings across the whole repo on my initial clone without me noticing.

I just force-pushed a clean version with only the 4 intended file modifications (with correct LF endings) and a single clean commit. It should be perfect for review now!

Please let me know if everything looks good. Thanks!

@abimaelmartell abimaelmartell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this together, the WASM direction is definitely useful.

One blocker: the WASM lopdf dependency still enables its default features, and cargo tree --target wasm32-unknown-unknown -e features shows that lopdf/default still pulls in lopdf/rayon and rayon. So this doesn’t fully disable threading for WASM yet.

Could you change the wasm target dependency to use default-features = false and then explicitly re-enable any non-threading features we still need? Also please run cargo fmt, since src/wasm.rs currently fails cargo fmt --check.

Thanks!

@devgabrielmarcondes

Copy link
Copy Markdown
Author

Thanks for the review!

I've just pushed an update addressing your feedback:

  • Explicitly set default-features = false for the wasm32 lopdf dependency to remove rayon.
  • Re-enabled the non-threading default features (chrono, jiff, and time).
  • Ran cargo fmt across the project to ensure everything follows the formatting standards.

Let me know if there's anything else needed!

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.

2 participants