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

[DevTools Bug]: App not recognized in Firefox, but works in Chrome #26860

Closed
Azeirah opened this issue May 26, 2023 · 23 comments
Closed

[DevTools Bug]: App not recognized in Firefox, but works in Chrome #26860

Azeirah opened this issue May 26, 2023 · 23 comments
Assignees

Comments

@Azeirah
Copy link

Azeirah commented May 26, 2023

Website or app

Repro steps

On both Firefox 103 and 104 the react devtools extension says: "This page doesn't appear to be using React".

On the most recent version of Chrome it's working just fine.

I cannot share the project since it's a private project unfortunately, but I suspect this is a regression introduced with the recent #26765

Especially since the devtools were working perfectly fine until maybe one or two weeks ago.

It does work in incognito mode in Firefox.

How often does this bug happen?

Every time

DevTools package (automated)

No response

DevTools version (automated)

No response

Error message (automated)

No response

Error call stack (automated)

No response

Error component stack (automated)

No response

GitHub query string (automated)

No response

@github-actions
Copy link

@Azeirah: We're sorry you've seen this error. ❤️

It looks like you forgot to specify a valid URL. (This means that we will not be able to reproduce the problem you're reporting.)

Please help us by providing a link to a CodeSandbox (https://codesandbox.io/s/new), a repository on GitHub, or a minimal code example that reproduces the problem. (Screenshots or videos can also be helpful if they help provide context on how to repro the bug.)

Here are some tips for providing a minimal example: https://stackoverflow.com/help/mcve

Issues without repros are automatically closed but we will re-open if you update with repro info.

@hoxyq
Copy link
Contributor

hoxyq commented May 26, 2023

Hey @Azeirah, thanks for reporting this.

Can you please specify the version of the extension you are using in Firefox?

@Azeirah
Copy link
Author

Azeirah commented May 26, 2023

It's version 4.27.8

@hoxyq
Copy link
Contributor

hoxyq commented May 26, 2023

It's version 4.27.8

I cannot reproduce it with Firefox both v113.0.2 and v104.0, so its probably something wrong on your end. If you can share more about your setup, I can try to help you with fixing that.

@Azeirah
Copy link
Author

Azeirah commented May 30, 2023

I'm running a React webapp served by apache2.

Without sharing sensitive code, this is how the app is initialized

const container = document.getElementById("root");
const root = createRoot(container);

root.render(
  // <React.StrictMode>
  <Provider store={store}>
    <LiveInterface />
    <App
      themeMode={"light"}
      theme={{
        typography: { fontSize: 32 },
      }}
    >
      <SessionState />
      <ErrorBoundary>
        <Restart />
        <Router />
      </ErrorBoundary>
    </App>
  </Provider>
  // </React.StrictMode>
);

Package.json

    ...
    "react": "^18.2.0",
    ...

I followed the troubleshooting steps

  • I'm not on a file:// url, I'm using a local http server.
  • The web application is running React
  • I'm not on Codepen
  • The app is not in an iFrame, not in a Chrome extension, is not a react native application and is not otherwise unusual (it's just a webapp)
  • I'm not on Chrome v101 or earlier (I'm on Firefox)

I find it odd that the global __REACT_DEVTOOLS_GLOBAL_HOOK__ is also not being set. If I understand it correctly it should even get set on sites that don't use react, right? Because it's how react initializes communication and communicates with the devtools. If I go to stackoverflow.com for example, the global is set. After removing various plugins, the devtools do inject the global. The devtools still don't recognize the application however.

Another odd thing I noticed is that one page of the same application does work (different react application on the same http server).

So

http://mydevserver.test/app/APP_ID // doesn't work
http://mydevserver.test/admin // react-based backoffice, does work. Uses react ^17.0.2

I followed the trace in the firefox debugger:

afbeelding

It looks like hook.checkDCE is false? I am using create react app with hot reloading, the backoffice/admin page does not use hot reloading. Could that be the issue?


I would like to note again that it does work in incognito mode. This is on a different computer, same setup and same app.

@hoxyq
Copy link
Contributor

hoxyq commented Jun 1, 2023

I'm running a React webapp served by apache2.

Without sharing sensitive code, this is how the app is initialized

const container = document.getElementById("root");
const root = createRoot(container);

root.render(
  // <React.StrictMode>
  <Provider store={store}>
    <LiveInterface />
    <App
      themeMode={"light"}
      theme={{
        typography: { fontSize: 32 },
      }}
    >
      <SessionState />
      <ErrorBoundary>
        <Restart />
        <Router />
      </ErrorBoundary>
    </App>
  </Provider>
  // </React.StrictMode>
);

Package.json

    ...
    "react": "^18.2.0",
    ...

I followed the troubleshooting steps

  • I'm not on a file:// url, I'm using a local http server.
  • The web application is running React
  • I'm not on Codepen
  • The app is not in an iFrame, not in a Chrome extension, is not a react native application and is not otherwise unusual (it's just a webapp)
  • I'm not on Chrome v101 or earlier (I'm on Firefox)

I find it odd that the global __REACT_DEVTOOLS_GLOBAL_HOOK__ is also not being set. If I understand it correctly it should even get set on sites that don't use react, right? Because it's how react initializes communication and communicates with the devtools. If I go to stackoverflow.com for example, the global is set. After removing various plugins, the devtools do inject the global. The devtools still don't recognize the application however.

Another odd thing I noticed is that one page of the same application does work (different react application on the same http server).

So

http://mydevserver.test/app/APP_ID // doesn't work
http://mydevserver.test/admin // react-based backoffice, does work. Uses react ^17.0.2

I followed the trace in the firefox debugger:

afbeelding

It looks like hook.checkDCE is false? I am using create react app with hot reloading, the backoffice/admin page does not use hot reloading. Could that be the issue?

I would like to note again that it does work in incognito mode. This is on a different computer, same setup and same app.

Do I understand correctly that it works for you in Firefox's incognito mode? This is strange, because we don't support it yet.

@Azeirah
Copy link
Author

Azeirah commented Jun 1, 2023

Do I understand correctly that it works for you in Firefox's incognito mode? This is strange, because we don't support it yet.

I thought so, but it's not the case. The plugin gives the notification that it can find react on the page, but the actual devtools don't load.

This is in Firefox incognito mode.

afbeelding


I'm also noticing that the devtools not loading seems almost random, on some page reloads they do load and on others they don't.

This gives me the feeling that there might be a race condition due to script loading order? If the plugin loads before React on the page, it works, if not, it won't.

@hoxyq
Copy link
Contributor

hoxyq commented Jun 2, 2023

Do I understand correctly that it works for you in Firefox's incognito mode? This is strange, because we don't support it yet.

I thought so, but it's not the case. The plugin gives the notification that it can find react on the page, but the actual devtools don't load.

This is in Firefox incognito mode.

I'm also noticing that the devtools not loading seems almost random, on some page reloads they do load and on others they don't.

This gives me the feeling that there might be a race condition due to script loading order? If the plugin loads before React on the page, it works, if not, it won't.

Too many factors that might influence it, this will be hard to debug without reproducible sample.
Can you try to run this application (which doesn't work with DevTools) locally (not on apache) and check if it works?

If problem is still present, I think you can create a repro from this point.

We still have different script injection logic for Firefox and not yet migrated to manifests v3 for Firefox, so this might be the reason why it works on Chrome and not on Firefox.

@Azeirah
Copy link
Author

Azeirah commented Jun 2, 2023

Can you try to run this application (which doesn't work with DevTools) locally (not on apache) and check if it works?

What do you mean by running it locally? I need a webserver to serve the application. With file:// it won't work according to the troubleshooting guide either, or am I misunderstanding you?

The application is running on a local webserver, jamezzv2.test is just a hostfile alias for localhost:somePort

@hoxyq
Copy link
Contributor

hoxyq commented Jun 2, 2023

Can you try to run this application (which doesn't work with DevTools) locally (not on apache) and check if it works?

What do you mean by running it locally? I need a webserver to serve the application. With file:// it won't work according to the troubleshooting guide either, or am I misunderstanding you?

The application is running on a local webserver, jamezzv2.test is just a hostfile alias for localhost:somePort

It should work with file://, troubleshooting guide specifies to toggle the required switch for Chrome.

Sorry I wasn't clear initially, just trying to check if there is a way to create a reproducible setup.

@Azeirah
Copy link
Author

Azeirah commented Jun 2, 2023

I recreated the app with file:// with a simple index.html importing the built application.

The devtools recognized the application 10 out of the 10 times that I reloaded it.

@jrjake
Copy link

jrjake commented Jun 12, 2023

Do you have Content-Security-Policy enabled? That will prevent extensions from running on your application in Firefox.

@Azeirah
Copy link
Author

Azeirah commented Jun 26, 2023

Do you have Content-Security-Policy enabled? That will prevent extensions from running on your application in Firefox.

This is not it ;( it's not enabled

@Azeirah
Copy link
Author

Azeirah commented Jul 25, 2023

I found the cause. The application I'm working is meant for different devices, and it turns out it's the simulated user-agent that causes the dev tools not to recognize the application.

I've been able to reproduce this in my development profile using Firefox dev edition as well as on Firefox stable edition on a clean profile.

  • Open page
  • Press ctrl+shift+m (mobile simulation, if on mac use dev tools to open mobile sim)
  • Add custom user agent, for example this one fails: Mozilla/5.0 (Linux; Android 11; SAMSUNG SM-G973U) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/14.2 Chrome/87.0.4280.141 Mobile Safari/537.36
  • Press enter to confirm
  • Dev tools do not recognize the page anymore after refresh

Without the custom user agent it consistently loads as expected.

@hoxyq
Copy link
Contributor

hoxyq commented Jul 25, 2023

I found the cause. The application I'm working is meant for different devices, and it turns out it's the simulated user-agent that causes the dev tools not to recognize the application.

I've been able to reproduce this in my development profile using Firefox dev edition as well as on Firefox stable edition on a clean profile.

  • Open page
  • Press ctrl+shift+m (mobile simulation, if on mac use dev tools to open mobile sim)
  • Add custom user agent, for example this one fails: Mozilla/5.0 (Linux; Android 11; SAMSUNG SM-G973U) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/14.2 Chrome/87.0.4280.141 Mobile Safari/537.36
  • Press enter to confirm
  • Dev tools do not recognize the page anymore after refresh

Without the custom user agent it consistently loads as expected.

Yeah, it is because of how we parse user agent.

This one fails because we look for Firefox here. This user agent doesn't state that it is Firefox-compatible, only Mozilla-compatible.

Can we close this issue? Seems like an expected behaviour.

@Azeirah
Copy link
Author

Azeirah commented Jul 25, 2023

If it's expected behavior, can this be added to the troubleshooting list at the very least? It took me weeks to figure out.

The one that's linked in this popup:
afbeelding

I understand that from a maintainer's perspective it's expected (user-agent != firefox), but from a developer's perspective it's not. From my perspective I'm just working on an application in mobile mode and suddenly the dev tools stop working. Why? No clue.

There's nothing documenting other than the code itself that the devtools are looking at your user-agent.

@hoxyq
Copy link
Contributor

hoxyq commented Jul 25, 2023

From my perspective I'm just working on an application in mobile mode and suddenly the dev tools stop working.

As you stated before, there were 2 different applications, and one of them patches user agent. I don't think this is a common case that should be listed somewhere in troubleshooting list.

I agree that we should display different popup with more readable explanation of whats going wrong. In your case, extension was trying to start, assuming that it was a Chromium-based browser and failed at some point. I don't know if you tried this before, but there is a way to debug extension in Firefox, and I think you will see errrors in this window's console.

I think the right way to handle this would be:

  1. Remove this assumption. If we have some weird unexpected user agent, where each flag is false, we should display new popup.
  2. Migrate to using navigator.userAgentData with a fallback to UA string parsing for Firefox.

Anyone interested in picking this up?

@Azeirah
Copy link
Author

Azeirah commented Jul 25, 2023

As you stated before, there were 2 different applications, and one of them patches user agent. I don't think this is a common case that should be listed somewhere in troubleshooting list.

This user agent is a default preset in Firefox mobile dev mode. This is not something I configured myself. That's why I expect it to happen to other people as well. IE, if you just press ctrl+shift+m and choose a device preset like the iPhone SE Firefox sets a user agent like the one I shared before.

This is the same as in Chrome, switching to the mobile emulator changes the user agent.

The logs are before turning on mobile sim and after.

Screenshot 2023-07-25 at 20 49 06

@hoxyq
Copy link
Contributor

hoxyq commented Jul 25, 2023

As you stated before, there were 2 different applications, and one of them patches user agent. I don't think this is a common case that should be listed somewhere in troubleshooting list.

This user agent is a default preset in Firefox mobile dev mode. This is not something I configured myself. That's why I expect it to happen to other people as well. IE, if you just press ctrl+shift+m and choose a device preset like the iPhone SE Firefox sets a user agent like the one I shared before.

This is the same as in Chrome, switching to the mobile emulator changes the user agent.

The logs are before turning on mobile sim and after.

Screenshot 2023-07-25 at 20 49 06

Oh, thanks for clarifying! We should definitely change this logic, and probably not depend on user agent string, when it comes to extension.

@hoxyq
Copy link
Contributor

hoxyq commented Aug 2, 2023

Hey @Azeirah, I've opened a PR with changes that should fix it - #27179.

Can you please try downloading and installing a custom build from here to check if it fixes the problem for you?

devtools.tgz should contain firefox-extension.zip archive, which then can be manually installed in Firefox. Please also consider removing original React DevTools extension from Firefox before that.

@Azeirah
Copy link
Author

Azeirah commented Aug 2, 2023

Hey @Azeirah, I've opened a PR with changes that should fix it - #27179.

Can you please try downloading and installing a custom build from here to check if it fixes the problem for you?

devtools.tgz should contain firefox-extension.zip archive, which then can be manually installed in Firefox. Please also consider removing original React DevTools extension from Firefox before that.

I will get back to you tomorrow when I'm at work. Thanks a lot for looking into it :)

@Azeirah
Copy link
Author

Azeirah commented Aug 3, 2023

It's working :)

@hoxyq
Copy link
Contributor

hoxyq commented Aug 3, 2023

It's working :)

Awesome, thanks for helping!

@Azeirah Azeirah closed this as completed Aug 4, 2023
hoxyq added a commit that referenced this issue Aug 29, 2023
…n user agent (#27179)

Fixes #26911,
#26860.

Currently, we are parsing user agent string to determine which browser
is running the extension. This doesn't work well with custom user
agents, and sometimes when user turns on mobile dev mode in Firefox, we
stop resolving that this is a Firefox browser, extension starts to use
Chrome API's and fails to inject.

Changes:
Since we are building different extensions for all supported browsers
(Chrome, Firefox, Edge), we predefine env variables for browser
resolution, which are populated in a build step.
EdisonVan pushed a commit to EdisonVan/react that referenced this issue Apr 15, 2024
…n user agent (facebook#27179)

Fixes facebook#26911,
facebook#26860.

Currently, we are parsing user agent string to determine which browser
is running the extension. This doesn't work well with custom user
agents, and sometimes when user turns on mobile dev mode in Firefox, we
stop resolving that this is a Firefox browser, extension starts to use
Chrome API's and fails to inject.

Changes:
Since we are building different extensions for all supported browsers
(Chrome, Firefox, Edge), we predefine env variables for browser
resolution, which are populated in a build step.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants