-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Service worker unable to initialize a wasm instance from base64 encoded url #512
Comments
Hey @Asuka109, thanks for opening this! I am thrilled to hear that you're working on a Chrome extension, and I want to help however I can. Before I can draft a fix, I need some information to know it will work. Could you provide a screenshot of the error (it sounds similar to #338) and whatever source code you have for your extension so far? I want to be able to test against it while I'm working on a solution. We'll get you unblocked in a jiffy. Thanks again for reaching out! |
@elijah-potter Thank you! I will working on an e2e case to reproduce the issue. |
I was try to repro this issue by writing a vitest case. But finally I gave up since it's so difficult to test a browser extension. ...So here is the repro repository: https://github.com/Asuka109/repro-harper-service-worker-cors > pnpm install
> pnpm playwright install
> pnpm build
> pnpm launch It will launch a browser instance with the extension loaded. You can go to chrome://extensions/ and click the "inspect view of service worker" button, and open any website in a new tab. So that you can the error below:
|
I am much more fimilar with webpack-based build tools. I will try to bundle the harper.js by using rslib. |
@elijah-potter Perhaps we can provide both the data URI and the url of a separated file as different exports. It would look like this: src/binary.ts export { default as inlinedBinary } from 'wasm/harper_wasm_bg.wasm?inline';
export { default as binary } from 'wasm/harper_wasm_bg.wasm?url'; Next, we should modify the Linter constructor to accept a import { WorkerLinter } from 'harper.js';
import { binary } from 'harper.js/binary';
const linter = new WorkerLinter({ binary }); // Alternatively, use `inlinedBinary`. Since Vite does tree shaking well, any unused binary exports will be removed. Feel free to assign this to me if it sounds good to you! |
That sounds like good solution. Go right on ahead! Don't be afraid to reach out here or on the Discord server if there are any questions you have. |
For reference: #607 seems to be where this is being worked on. |
I am trying to build a Chrome browser extension based on the Manifest V3 API for Harper. I encountered some issues when instantiating the Linter in the service worker:
According to Chrome's requirements, the wasm module should be bundled and distributed as a separate file along with the service worker and all other assets.
The text was updated successfully, but these errors were encountered: