Screen sharing error

I need to enable user screen sharing for my project. I used this example from the documentation - Screen sharing documentation. It works great on my Mac with Google Chrome. Unfortunately, Firefox gives me this JS error:

getDisplayMedia requires transient activation from a user gesture.

instead of asking for permission as Chrome does. Any idea, what can be wrong?

Try this: openvidu-insecure-js-screen-share - OpenVidu Docs

When some browser complains about “something requiring a user gesture” it means that the API you are trying to use is considered critical and for that reason it requires a user gesture to be the trigger of the action. For example, the click of a button. It seems that Firefox in this case is requiring that, but your application is requesting access to the screen sharing API (the initialization of the OpenVidu Publisher’s object) without a user gesture.
If you encapsulate the Publisher’s initialization after a user gesture, you’ll see the problem go away.