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

Overriding console methods throws #2330

Open
ChipZhang opened this issue Jan 13, 2025 · 3 comments
Open

Overriding console methods throws #2330

ChipZhang opened this issue Jan 13, 2025 · 3 comments
Labels
Milestone

Comments

@ChipZhang
Copy link

ChipZhang commented Jan 13, 2025

Since userjs is unusual environment, react devtools browser extensions fails to inspect react code running in such environments.
I try to use the standalone method:

  1. start a local react devtools server (npx react-devtools)
  2. connect to this server in the script targeting unusual environment (the script will be bundled using webpack):
import {initialize, connectToDevTools} from 'react-devtools-core/backend';
initialize();
connectToDevTools({host: 'localhost', port: 8097, useHttps: false});

This method works well for script running in a normal web page, in violentmonkey or in webext extensions. But fails for Tampermonkey.

The error is like:

TypeError: Cannot set property error of [object Object] which has only a getter

After hours of research, I figured out this is cause by the code here. The code tries to overwrite built-in console.error with custom handling function.

It seems console.xxx in Tampermonkey environment is read only, thus those errors.

@ChipZhang ChipZhang changed the title Failed to run stanalone react-devtools in userjs Failed to run standalone react-devtools Jan 13, 2025
@7nik
Copy link

7nik commented Jan 13, 2025

Have you tried vite-plugin-monkey? It seems to support React dev tools.

@ChipZhang
Copy link
Author

ChipZhang commented Jan 15, 2025

I've found out that the browser extension just DO work.
It's my fault. I just believed it won't work and didn't give it a try before.

But still there are problems:

  1. The extension version may report lots of false positive warnings/errors, e.g.:

Warning: Invalid hook call. Hooks can only be called inside of the body of a function component.

The same code won't report those warnings/errors in other environment, e.g.: ViomentMonkey + standlone devtools.

  1. The standalone version may solve the first problem, but it fails to work in TamperMonkey due to the reasons described in OP.

@derjanb derjanb changed the title Failed to run standalone react-devtools Overriding console methods throws Jan 16, 2025
@derjanb derjanb added this to the 5.4 milestone Jan 16, 2025
@derjanb derjanb added the bug label Jan 16, 2025
@derjanb
Copy link
Member

derjanb commented Jan 16, 2025

It seems console.xxx in Tampermonkey environment is read only, thus those errors.

Will be fixed at the next beta version.

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

No branches or pull requests

3 participants