Skip to content

Commit 3f6f6df

Browse files
authored
fix: align inline baseUrl with IFrame origin (#76)
* 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 * docs: update TSDoc for webViewUrl/inline behavior
1 parent a4784e6 commit 3f6f6df

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

.changeset/fresh-drinks-slide.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"react-native-youtube-bridge": patch
3+
---
4+
5+
fix: align inline baseUrl with IFrame origin
6+
7+
- add trailing-slash handling for WebView baseUrl in inline mode
8+
- propagate origin/playerVars into local HTML
9+
- refine YoutubeView WebView source resolution

.changeset/slow-kings-lay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-native-youtube-bridge": patch
3+
---
4+
5+
docs: update TSDoc for webViewUrl/inline behavior

packages/react-native-youtube-bridge/src/YoutubeView.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ function YoutubeView({
4040
// biome-ignore lint/correctness/useExhaustiveDependencies: webViewProps.source is intentionally excluded to prevent unnecessary re-renders
4141
const webViewSource = useMemo(() => {
4242
if (useInlineHtml) {
43+
const webViewBaseUrlWithSlash =
44+
webViewBaseUrl && (webViewBaseUrl.endsWith('/') ? webViewBaseUrl : `${webViewBaseUrl}/`);
45+
4346
return {
4447
html: createPlayerHTML(),
45-
baseUrl: webViewBaseUrl ?? 'https://localhost/',
48+
baseUrl: webViewBaseUrlWithSlash || 'https://localhost/',
4649
};
4750
}
4851

@@ -111,7 +114,7 @@ function YoutubeView({
111114
}
112115
} catch (error) {
113116
if (__DEV__) {
114-
console.error('Error parsing WebView message:', error);
117+
console.error('Error parsing WebView message:', error, event?.nativeEvent?.data);
115118
}
116119
player.emit('error', { code: 1000, message: 'FAILED_TO_PARSE_WEBVIEW_MESSAGE' });
117120
}

packages/react-native-youtube-bridge/src/hooks/useCreateLocalPlayerHtml.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const useCreateLocalPlayerHtml = ({
2525
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>';
2626
}
2727

28-
const safeOrigin = escapeHtml(origin) ?? 'https://localhost';
28+
const safeOrigin = escapeHtml(origin) || 'https://localhost';
2929
const safeStartTime = safeNumber(startTime);
3030
const safeEndTime = endTime ? safeNumber(endTime) : undefined;
3131

packages/react-native-youtube-bridge/src/types/youtube.ts

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

0 commit comments

Comments
 (0)