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

Script fails to load with react 18 and iOS #93

Open
henninghaakonsen opened this issue May 31, 2022 · 0 comments
Open

Script fails to load with react 18 and iOS #93

henninghaakonsen opened this issue May 31, 2022 · 0 comments

Comments

@henninghaakonsen
Copy link

Hi, our team has tried to use your package (and implement it ourself), but we are facing the same issue either way. When trying to load an youtube video on iOS the script fails to load. There is little to no information in the errors from the onerror function and we were wondering if you have any ideas as to how we can fix this issue.

useEffect(() => {
    if (!window.YT) {
      // If not, load the script asynchronously
      const tag = document.createElement('script');
      tag.src = 'https://www.youtube.com/iframe_api';
      tag.onerror = (
        event: Event | string,
        source?: string,
        lineno?: number,
        colno?: number,
        error?: Error
      ) => {
        console.log(event, source, error); // Most of these are undefined
      };

      // onYouTubeIframeAPIReady will set the toggle after the script is loaded
      window.onYouTubeIframeAPIReady = onYouTubeIframeAPIReady;

      const firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag?.parentNode?.insertBefore(tag, firstScriptTag);
    } else {
      // If script is already there, load the video directly
      onYouTubeIframeAPIReady();
    }
}, []);

const onYouTubeIframeAPIReady = () => {
    setIsYoutubeIframeApiReady(true); // this enables child components to create new players with "new window.YT.Player()"
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant