Skip to content

transpileToJS feature#46

Open
BaderBC wants to merge 4 commits into
wasm-tool:masterfrom
BaderBC:js-transpiler-feature
Open

transpileToJS feature#46
BaderBC wants to merge 4 commits into
wasm-tool:masterfrom
BaderBC:js-transpiler-feature

Conversation

@BaderBC

@BaderBC BaderBC commented Jul 7, 2024

Copy link
Copy Markdown

Adds option to transpile wasm to JS using wasm2js tool.
This feature would be great for old browser support as well as e.g. writing chrome extensions (which is why I am doing this pr), because chrome doesn't allow usage of wasm in their extensions.

@Pauan

Pauan commented Jul 8, 2024

Copy link
Copy Markdown
Collaborator

I also create Chrome extensions with Rust, have you seen this section of the README?

https://github.com/wasm-tool/rollup-plugin-rust?tab=readme-ov-file#chrome--firefox-extensions

@BaderBC

BaderBC commented Jul 8, 2024

Copy link
Copy Markdown
Author

Yes I saw it.
It works perfectly fine with firefox and chrome with manifest version 2, but in the third version of manifest google forbidden usage of inline wasm.

image

When using inlineWasm option, we basically store wasm output in variable, which chrome treets as a remote wasm execution.

@BaderBC

BaderBC commented Jul 8, 2024

Copy link
Copy Markdown
Author

I made a few changes. I think I'm done with this pr.
Let me know, @Pauan, whether you decide to merge or close this pr.

Thanks for your time!

@Pauan

Pauan commented Jul 15, 2024

Copy link
Copy Markdown
Collaborator

Sorry for the delay on this, I've been quite busy, but I plan to look at this soon.

@BaderBC

BaderBC commented Jul 30, 2024

Copy link
Copy Markdown
Author

Sorry for the delay on this, I've been quite busy, but I plan to look at this soon.

Let me give you a friendly reminder @Pauan 😅

@Pauan

Pauan commented Aug 4, 2024

Copy link
Copy Markdown
Collaborator

@BaderBC Thanks for the reminder!

So I checked, and this plugin works completely fine with Chrome extensions (including manifest 3).

I created a simple example, which you can build with yarn install && yarn build:

https://github.com/Pauan/rust-dominator/tree/c53b2d8a0ab3c134a62a33d19b1cceec4634b09b/examples/extension

Then you just load the dist folder as an unpacked extension.


You do need to specify wasm-unsafe-eval in your manifest's content_security_policy. This is normal and expected:

https://developer.chrome.com/docs/extensions/reference/manifest/content-security-policy

The policy you mentioned before is only for remote code (such as loaded with HTTP), it doesn't apply to files which are bundled with the extension. So it's completely fine to use Wasm with Chrome extensions.

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