Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/true-cobras-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"react-native-youtube-bridge": patch
---

fix: add missing origin parameter for YouTube iframe API security
- Pass webViewUrl as origin parameter to resolve iframe API restrictions
- Fix embed access issues when enablejsapi=1 is used
5 changes: 3 additions & 2 deletions src/hooks/useYoutubePlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const useYouTubePlayer = (config: YoutubePlayerConfig) => {
onAutoplayBlocked,
} = config;

const { startTime, endTime, autoplay, controls, loop, muted, playsinline, rel } = playerVars;
const { startTime, endTime, autoplay, controls, loop, muted, playsinline, rel, origin } = playerVars;

const cleanup = useCallback(() => {
coreRef.current?.destroy();
Expand Down Expand Up @@ -68,6 +68,7 @@ const useYouTubePlayer = (config: YoutubePlayerConfig) => {
rel,
startTime,
endTime,
origin,
},
});
} catch (error) {
Expand All @@ -80,7 +81,7 @@ const useYouTubePlayer = (config: YoutubePlayerConfig) => {
};

initialize();
}, [videoId, startTime, endTime, autoplay, controls, loop, muted, playsinline, rel, onError]);
}, [videoId, startTime, endTime, autoplay, controls, loop, muted, playsinline, rel, origin, onError]);

useEffect(() => {
if (isReady && videoId && coreRef.current) {
Expand Down
1 change: 1 addition & 0 deletions src/modules/YouTubePlayerCore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class YouTubePlayerCore {
end: config.playerVars?.endTime,
playsinline: config.playerVars?.playsinline ? 1 : 0,
rel: config.playerVars?.rel ? 1 : 0,
origin: config.playerVars?.origin,
enablejsapi: 1,
},
events: {
Expand Down
7 changes: 5 additions & 2 deletions src/utils/youtube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ export const getYoutubeWebViewUrl = (
return '';
}

const { startTime, autoplay, controls, loop, muted, playsinline, rel, endTime } = playerVars;
const baseUrl = webViewBaseUrl || DEFAULT_EXTERNAL_WEB_URL;

const url = new URL(webViewBaseUrl || DEFAULT_EXTERNAL_WEB_URL);
const { startTime, autoplay, controls, loop, muted, playsinline, rel, endTime, origin } = playerVars;

const url = new URL(baseUrl);

url.searchParams.set('videoId', videoId);
startTime && url.searchParams.set('startTime', startTime.toString());
endTime && url.searchParams.set('endTime', endTime.toString());
url.searchParams.set('origin', origin || baseUrl);
url.searchParams.set('autoplay', autoplay ? 'true' : 'false');
url.searchParams.set('controls', controls ? 'true' : 'false');
url.searchParams.set('loop', loop ? 'true' : 'false');
Expand Down
2 changes: 2 additions & 0 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function App() {
const muted = urlParams.get('muted') === 'true';
const playsinline = urlParams.get('playsinline') === 'true';
const rel = urlParams.get('rel') === 'true';
const origin = urlParams.get('origin') ?? '';

const [progressInterval, setProgressInterval] = useState<number>(0);

Expand All @@ -30,6 +31,7 @@ function App() {
videoId: youtubeVideoId,
progressInterval,
playerVars: {
origin,
controls,
autoplay,
muted,
Expand Down