Skip to content
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

Creating a WebWorker inside a WebWorker will the self.origin value being null. #17507

Open
7 tasks done
hughfenghen opened this issue Jun 18, 2024 · 1 comment · May be fixed by #17509
Open
7 tasks done

Creating a WebWorker inside a WebWorker will the self.origin value being null. #17507

hughfenghen opened this issue Jun 18, 2024 · 1 comment · May be fixed by #17509

Comments

@hughfenghen
Copy link

hughfenghen commented Jun 18, 2024

Describe the bug

When the origin value is null, calling some APIs can trigger SecurityError or Cross-Origin error.

For example, executing await navigator.storage.getDirectory()
will throw the error: Error: SecurityError: Storage directory access is denied.

The reason is that a WebWorker was created using a Data URL.
image

The corresponding Vite code is at: https://github.com/vitejs/vite/blob/7b240e408ed83f172e9f88823eae3b4a9ba92674/packages/vite/src/node/plugins/worker.ts#L326C28-L326C38

I tried replacing self with window, which resolved the issue.

Reproduction

https://stackblitz.com/edit/vitejs-vite-hfhdfg?file=main.js

Steps to reproduce

  1. npm run build
  2. check dist/assets/index-[hash].js

System Info

N/A

Used Package Manager

npm

Logs

No response

Validations

Copy link

stackblitz bot commented Jun 18, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant