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
9 changes: 9 additions & 0 deletions .changeset/fresh-drinks-slide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"react-native-youtube-bridge": patch
---

fix: align inline baseUrl with IFrame origin

- add trailing-slash handling for WebView baseUrl in inline mode
- propagate origin/playerVars into local HTML
- refine YoutubeView WebView source resolution
5 changes: 5 additions & 0 deletions .changeset/slow-kings-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-native-youtube-bridge": patch
---

docs: update TSDoc for webViewUrl/inline behavior
7 changes: 5 additions & 2 deletions packages/react-native-youtube-bridge/src/YoutubeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ function YoutubeView({
// biome-ignore lint/correctness/useExhaustiveDependencies: webViewProps.source is intentionally excluded to prevent unnecessary re-renders
const webViewSource = useMemo(() => {
if (useInlineHtml) {
const webViewBaseUrlWithSlash =
webViewBaseUrl && (webViewBaseUrl.endsWith('/') ? webViewBaseUrl : `${webViewBaseUrl}/`);

return {
html: createPlayerHTML(),
baseUrl: webViewBaseUrl ?? 'https://localhost/',
baseUrl: webViewBaseUrlWithSlash || 'https://localhost/',
};
}

Expand Down Expand Up @@ -111,7 +114,7 @@ function YoutubeView({
}
} catch (error) {
if (__DEV__) {
console.error('Error parsing WebView message:', error);
console.error('Error parsing WebView message:', error, event?.nativeEvent?.data);
}
player.emit('error', { code: 1000, message: 'FAILED_TO_PARSE_WEBVIEW_MESSAGE' });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const useCreateLocalPlayerHtml = ({
return '<html><body><div style="width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; color: #fff;">Invalid YouTube ID</div></body></html>';
}

const safeOrigin = escapeHtml(origin) ?? 'https://localhost';
const safeOrigin = escapeHtml(origin) || 'https://localhost';
const safeStartTime = safeNumber(startTime);
const safeEndTime = endTime ? safeNumber(endTime) : undefined;

Expand Down
5 changes: 3 additions & 2 deletions packages/react-native-youtube-bridge/src/types/youtube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ export type YoutubeViewProps = {
* The URL for the WebView source.
* @remark
* When `useInlineHtml` is `true`, this value is set as the `baseUrl` for HTML content.
* In this case, the origin of `webViewUrl` MUST match the YouTube IFrame API `origin`
* (e.g. baseUrl `https://localhost/` ⇄ origin `https://localhost`).
* In this case, the origin of `webViewUrl` MUST exactly match the YouTube IFrame API `origin`.
* - Include the port when applicable (e.g. baseUrl `https://localhost:8081/` ⇄ origin `https://localhost:8081`).
* - Use a trailing slash on the `baseUrl`, but not on `origin` (scheme + host [+ port] only).
*
* When `useInlineHtml` is `false`, this value overrides the default URI for the WebView source (https://react-native-youtube-bridge.pages.dev).
* @platform ios, android
Expand Down