WebGL: How to embed content from sites like YouTube, Twitch, or Vimeo?

2D WebView for WebGL has a limitation where it's unable to load web pages that explicitly block being embedded by another site. Many popular websites block their main site from being embedded by another site, but they offer specific embed URLs that can be embedded by other sites. For example, 2D WebView for WebGL is unable to load the main YouTube home page because YouTube blocks it from being embedded, but 2D WebView is able to load YouTube embed URLs, like this one: https://www.youtube.com/embed/y03ko-FyHjY. Here are the steps for loading an embed URL with 2D WebView:

  1. Follow the website's instructions to generate HTML code for the embed. Here are links to the instructions for some popular sites:

  2. Locate the URL contained in the HTML code from step #1. The URL should be the src attribute of an <iframe> tag. Here's an example from YouTube's Share -> Embed screen:

YouTube embed code

  1. Load the URL from step #2 into your CanvasWebViewPrefab, by setting its Initial URL field in the editor or by calling IWebView.LoadUrl() via script. If you want to quickly test your embed URL, you can do so by loading it in the WebGL webview demo page.