Skip to content

Conversation

@saseungmin
Copy link
Member

@saseungmin saseungmin commented Jun 21, 2025

  • Pass webViewUrl as origin parameter to resolve iframe API restrictions
  • Fix embed access issues when enablejsapi=1 is used

Summary by CodeRabbit

  • Bug Fixes
    • Resolved access and functionality issues with embedded YouTube videos by correctly passing the "origin" parameter when initializing the YouTube iframe API. This ensures better compatibility and prevents restrictions when using the "enablejsapi=1" parameter.

- Pass webViewUrl as origin parameter to resolve iframe API restrictions
- Fix embed access issues when enablejsapi=1 is used
@changeset-bot
Copy link

changeset-bot bot commented Jun 21, 2025

🦋 Changeset detected

Latest commit: 1d3e3d8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
react-native-youtube-bridge Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Jun 21, 2025

Walkthrough

This update introduces the handling of the origin parameter throughout the YouTube player integration. The origin is now extracted, passed, and set in relevant places, ensuring proper initialization and communication with the YouTube iframe API. These changes address security and access issues when embedding YouTube videos with JavaScript API enabled.

Changes

File(s) Change Summary
.changeset/true-cobras-appear.md Documents the addition of the origin parameter for the YouTube iframe API.
src/hooks/useYoutubePlayer.ts Adds origin to player initialization, dependency array, and playerVars object.
src/modules/YouTubePlayerCore.tsx Passes origin from config to the YouTube Player constructor's playerVars.
src/utils/youtube.ts Updates getYoutubeWebViewUrl to handle and set the origin query parameter in the constructed URL.
web/src/App.tsx Extracts origin from the URL query string and includes it in playerVars for the YouTube player hook.

Sequence Diagram(s)

sequenceDiagram
    participant Browser
    participant App (web/src/App.tsx)
    participant useYoutubePlayer Hook
    participant YouTubePlayerCore
    participant YouTube Iframe API

    Browser->>App (web/src/App.tsx): Loads page with URL (may include ?origin=...)
    App (web/src/App.tsx)->>useYoutubePlayer Hook: Passes playerVars (including origin)
    useYoutubePlayer Hook->>YouTubePlayerCore: Initializes player with playerVars (origin included)
    YouTubePlayerCore->>YouTube Iframe API: Creates player with enablejsapi=1 and origin param
    YouTube Iframe API-->>YouTubePlayerCore: Validates and sets up player
Loading

Poem

In the warren of code, a hop and a spin,
The origin now joins, let the YouTube play begin!
No more iframe woes or API dismay,
With origins aligned, videos will play.
A carrot for the coder, a hop for the patch—
Now every bunny’s YouTube dreams will match!
🥕✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 358e706 and 1d3e3d8.

📒 Files selected for processing (5)
  • .changeset/true-cobras-appear.md (1 hunks)
  • src/hooks/useYoutubePlayer.ts (3 hunks)
  • src/modules/YouTubePlayerCore.tsx (1 hunks)
  • src/utils/youtube.ts (1 hunks)
  • web/src/App.tsx (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/utils/youtube.ts (1)
src/utils/constants.ts (1)
  • DEFAULT_EXTERNAL_WEB_URL (1-1)
🔇 Additional comments (11)
web/src/App.tsx (2)

18-18: LGTM! Consistent parameter extraction pattern.

The origin parameter extraction follows the established pattern used for other URL parameters with an appropriate empty string fallback.


34-34: LGTM! Origin parameter properly passed to player configuration.

The origin is correctly included in the playerVars object and will be propagated through the YouTube player initialization.

src/modules/YouTubePlayerCore.tsx (1)

103-103: LGTM! Origin parameter correctly integrated into YouTube Player configuration.

The origin parameter is properly added to the playerVars object using the same pattern as other parameters, with appropriate optional chaining to handle undefined values.

.changeset/true-cobras-appear.md (1)

1-8: LGTM! Clear and comprehensive changelog entry.

The changelog accurately documents the security fix and explains the specific issues resolved by adding the origin parameter to the YouTube iframe API initialization.

src/hooks/useYoutubePlayer.ts (3)

23-23: LGTM! Origin parameter properly destructured from playerVars.

The origin parameter is correctly added to the destructuring assignment, following the established pattern for other player variables.


71-71: LGTM! Origin correctly passed to player configuration.

The origin parameter is properly included in the playerVars object passed to the createPlayer method.


84-84: LGTM! Origin correctly added to dependency array.

Including origin in the dependency array ensures the player reinitializes when the origin parameter changes, which is the correct behavior for this security-related parameter.

src/utils/youtube.ts (4)

14-14: LGTM! Good refactoring to extract baseUrl variable.

Extracting the baseUrl improves code readability and allows for reuse in the origin parameter fallback logic.


16-16: LGTM! Origin parameter properly added to destructuring.

The origin parameter is correctly included in the playerVars destructuring, maintaining consistency with the other parameter extractions.


18-18: LGTM! Consistent use of baseUrl variable.

Using the extracted baseUrl variable maintains consistency and improves code maintainability.


23-23: LGTM! Smart origin parameter handling with sensible fallback.

The origin parameter is set with a logical fallback to baseUrl when no explicit origin is provided. This ensures the YouTube iframe API always receives an origin parameter, which is important for security and proper functionality.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@saseungmin saseungmin merged commit ea4af1b into main Jun 21, 2025
7 checks passed
@saseungmin saseungmin deleted the fix/youtube-iframe-origin-parameter branch June 21, 2025 16:02
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

Successfully merging this pull request may close these issues.

2 participants