useMediaQuery causes error in Firefox browser extension content script #44986
Labels
hook: useMediaQuery
status: waiting for maintainer
These issues haven't been looked at yet by a maintainer
Steps to reproduce
Steps:
Current behavior
The example extension calls
useMediaQuery("(prefers-color-scheme: dark)")
and renders "Prefer dark: Yes/No" on the pageBehavior in Chrome:
In Firefox, the content script crashes with error
Expected behavior
Using useMediaQuery should not crash the script in Firefox
Context
Offending line
This might be a fairly niche use case, but a similar issue can be found here facebook/react#16606.
I was able to fix this by replacing this line in
mui-system/src/useMediaQuery/useMediaQuery.ts
with
I don't know what exactly causes the issue in Firefox alone but looks like it has something to do with saving
window
methods to a variable and calling that variable.Your environment
System:
OS: Windows 11 10.0.26100
Binaries:
Node: 20.12.1 - C:\Program Files\nodejs\node.EXE
npm: 10.5.0 - C:\Program Files\nodejs\npm.CMD
pnpm: 9.15.2 - C:\Program Files\nodejs\pnpm.CMD
Browsers:
Google Chrome 131.0.6778.265
Firefox Developer Edition 135.0b2
npmPackages:
@emotion/react: ^11.14.0 => 11.14.0
@emotion/styled: ^11.14.0 => 11.14.0
@mui/icons-material: ^6.3.0 => 6.3.1
@mui/material: ^6.3.0 => 6.3.1
@mui/system: ^6.3.0 => 6.3.1
@types/react: ^19.0.2 => 19.0.4
react: 19.0.0 => 19.0.0
react-dom: 19.0.0 => 19.0.0
typescript: ^5.7.2 => 5.7.3
Search keywords: extension firefox useMediaQuery matchMedia
The text was updated successfully, but these errors were encountered: