GithubHelp home page GithubHelp logo

OT is not defined about opentok-react HOT 12 CLOSED

opentok avatar opentok commented on September 3, 2024
OT is not defined

from opentok-react.

Comments (12)

alveshelio avatar alveshelio commented on September 3, 2024 1

Hi @aiham,

Thank you very much for your precious help. Actually I was getting this error because I was using package: browser-policy, you've put me in the right track.

I simply need to add this to my code:

Meteor.startup( () => {
  BrowserPolicy.content.allowInlineScripts('static.opentok.com');
  BrowserPolicy.content.allowOriginForAll('static.opentok.com');
})

Here's an article talking about it: Using the Browser Policy Package

Thank you again for your help.

from opentok-react.

aiham avatar aiham commented on September 3, 2024

@alveshelio Thanks for using opentok-react!

You would get OT is not defined if you haven't included opentok.js before your application. Have you followed the following instruction from the README:

Include opentok.js before your application:
<script src="//static.opentok.com/v2/js/opentok.min.js"></script>

If you have done that, maybe you can give me more information about your setup because nothing else comes to mind.

from opentok-react.

alveshelio avatar alveshelio commented on September 3, 2024

Hi @aiham,

I had not added this script.
I'm not sure about this one:

Include opentok.js before your application:

<script src="//static.opentok.com/v2/js/opentok.min.js"></script>

I've added <script src="//static.opentok.com/v2/js/opentok.min.js"></script> to my main.html file, this is what I have:

<body>
  <div id="react-root"></div>
  <script src="//static.opentok.com/v2/js/opentok.min.js"></script>
</body>

Because the tutorial says, include opentok.js before your application and I've checked your example and you are indeed loading this before the bundle.js file. However, I'm using Meteor and in my html file I do not have the bundle.js file that is called.

When I add <script src="//static.opentok.com/v2/js/opentok.min.js"></script> right before the tag, I get this error:
Refused to load the script 'http://static.opentok.com/v2/js/opentok.min.js' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-inline'".

from opentok-react.

aiham avatar aiham commented on September 3, 2024

@alveshelio I just deleted my previous comment, I believe it's wrong.

I think you should load opentok.js using https:

<script src="https://static.opentok.com/v2/js/opentok.min.js"></script>

I will update the README now.

from opentok-react.

alveshelio avatar alveshelio commented on September 3, 2024

Hi @aiham,

Unfortunately with both methods:
meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline' static.opentok.com"
and

<script src="https://static.opentok.com/v2/js/opentok.min.js"></script>

I'm still getting the same error.

I've tried on Chrome, Firefox and Safary and I have the same error in all three.

from opentok-react.

aiham avatar aiham commented on September 3, 2024

@alveshelio What if you try adding the following before </head>:

<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline' static.opentok.com">

This is setting a Content Security Policy which trusts static.opentok.com. See:

I suspect Meteor is setting a Content Security Policy which only trusts the same origin. Can you open your page with the dev tools open, navigate to the Network tab and click on the request which loads the HTML page. Can you see if there is a response header called Content-Security-Policy there?

from opentok-react.

alveshelio avatar alveshelio commented on September 3, 2024

so I've added
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline' static.opentok.com">

and checked the Network tab, in "XHR" I don't see anything related to Content-Security-Policy, in "Other" i see "opentok.min.js" withs Status "(blocked:scp)"

from opentok-react.

aiham avatar aiham commented on September 3, 2024

@alveshelio The CSP header will be in the network request for the HTML page itself, not XHR. Open the network tab and press refresh, it should be the first request in the list.

from opentok-react.

alveshelio avatar alveshelio commented on September 3, 2024

I don't see any SCP at the top, here's what I have: http://prntscr.com/e8fn9l

The request to opentok.min.js comes almost at the end, check here: http://prntscr.com/e8fmzp,

from opentok-react.

aiham avatar aiham commented on September 3, 2024

@alveshelio What about before Clipper.js? There must be a HTML page that loads first. You need to press refresh after you open the dev tools

from opentok-react.

aiham avatar aiham commented on September 3, 2024

Also, the Content Security Policy is shown once you click on the request, under the Response Headers section:

image

from opentok-react.

aiham avatar aiham commented on September 3, 2024

I haven't got much experience with Meteor so I can't say for sure, but it's probably adding the CSP header. You will likely need to add static.opentok.com to the list of trusted domains for static content. There is likely a module to help you with this: https://blog.meteor.com/defense-in-depth-securing-meteor-apps-with-content-security-policy-8fd5ffa503ee

from opentok-react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.