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

fix: prevent error in service worker environment #384

Merged
merged 2 commits into from
Jun 20, 2024

Conversation

chidg
Copy link
Contributor

@chidg chidg commented Jun 19, 2024

In Chromium extensions under Manifest Version 3, the project throws an error:
Screenshot 2024-06-18 at 3 27 00 PM

This is because in service workers, window is not defined, so isBrowser is false, but process is also not defined by default.

This could not be fixed by webpack's DefinePlugin because of the optional chaining; the optionally-chained expression actually gets transpiled to something quite different in the built package - typeof process?.env?.TXWRAPPER_METADATA_CACHE_MAX !== 'undefined' becomes typeof ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.TXWRAPPER_METADATA_CACHE_MAX) !== 'undefined', which DefinePlugin can't parse.

Currently in Talisman as we transition to MV3 we're dealing with this by monkey patching a process global variable into the service worker, however we'd like to avoid this if possible.

@chidg chidg requested a review from a team as a code owner June 19, 2024 03:20
@chidg chidg changed the title Prevent error in service worker environment fix: prevent error in service worker environment Jun 19, 2024
Copy link
Member

@TarikGul TarikGul left a comment

Choose a reason for hiding this comment

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

Seems sane to me! Thanks for the PR.

Copy link
Collaborator

@IkerAlus IkerAlus left a comment

Choose a reason for hiding this comment

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

Thanks!

@TarikGul
Copy link
Member

@chidg Just needs yarn lint:fix ran on it.

@TarikGul TarikGul merged commit 6145ea6 into paritytech:main Jun 20, 2024
6 checks passed
@chidg
Copy link
Contributor Author

chidg commented Jun 20, 2024

Thanks for the quick review and merge!

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.

None yet

3 participants