Skip to content

Support start timestamps, fix Shorts & Live embed URLs #6234

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

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

purfectliterature
Copy link

@purfectliterature purfectliterature commented Apr 3, 2025

Start timestamps are currently not embedded with youtu.be and youtube.com/watch URLs. There are also inconsistencies with how youtu.be and youtube.com/watch URLs are parsed, and with how search params in the original URL are being handled.

This PR refactors the getEmbedUrlFromYoutubeUrl function to use the native URL object to create the embed URL. It also converts the start timestamps like t=10 in youtu.be and t=10s in youtube.com/watch to start=10 in youtube.com/embed URLs. This should resolve #5765.

As an added bonus, it also appears that Shorts URLs are not embedded correctly. It's fixed in this PR. While I'm at it, I also added support for Live URLs, so this PR closes #5447 too.

Checklist

  • I have created a changeset for this PR if necessary.
  • My changes do not break the library.
  • I have added tests where applicable.
  • I have followed the project guidelines.
  • I have fixed any lint issues.

Copy link

changeset-bot bot commented Apr 3, 2025

🦋 Changeset detected

Latest commit: b337825

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

This PR includes changesets to release 54 packages
Name Type
@tiptap/extension-youtube Major
@tiptap/core Major
@tiptap/extension-blockquote Major
@tiptap/extension-bold Major
@tiptap/extension-bubble-menu Major
@tiptap/extension-bullet-list Major
@tiptap/extension-character-count Major
@tiptap/extension-code-block-lowlight Major
@tiptap/extension-code-block Major
@tiptap/extension-code Major
@tiptap/extension-collaboration-cursor Major
@tiptap/extension-collaboration Major
@tiptap/extension-color Major
@tiptap/extension-document Major
@tiptap/extension-dropcursor Major
@tiptap/extension-floating-menu Major
@tiptap/extension-focus Major
@tiptap/extension-font-family Major
@tiptap/extension-gapcursor Major
@tiptap/extension-hard-break Major
@tiptap/extension-heading Major
@tiptap/extension-highlight Major
@tiptap/extension-history Major
@tiptap/extension-horizontal-rule Major
@tiptap/extension-image Major
@tiptap/extension-italic Major
@tiptap/extension-link Major
@tiptap/extension-list-item Major
@tiptap/extension-list-keymap Major
@tiptap/extension-mention Major
@tiptap/extension-ordered-list Major
@tiptap/extension-paragraph Major
@tiptap/extension-placeholder Major
@tiptap/extension-strike Major
@tiptap/extension-subscript Major
@tiptap/extension-superscript Major
@tiptap/extension-table-cell Major
@tiptap/extension-table-header Major
@tiptap/extension-table-row Major
@tiptap/extension-table Major
@tiptap/extension-task-item Major
@tiptap/extension-task-list Major
@tiptap/extension-text-align Major
@tiptap/extension-text-style Major
@tiptap/extension-text Major
@tiptap/extension-typography Major
@tiptap/extension-underline Major
@tiptap/html Major
@tiptap/pm Major
@tiptap/react Major
@tiptap/starter-kit Major
@tiptap/suggestion Major
@tiptap/vue-2 Major
@tiptap/vue-3 Major

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

Copy link

netlify bot commented Apr 3, 2025

Deploy Preview for tiptap-embed ready!

Name Link
🔨 Latest commit b337825
🔍 Latest deploy log https://app.netlify.com/sites/tiptap-embed/deploys/67ee761e4c4f4e00084a7b81
😎 Deploy Preview https://deploy-preview-6234--tiptap-embed.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@bdbch bdbch changed the base branch from develop to next April 17, 2025 16:56
@bdbch bdbch changed the base branch from next to main April 17, 2025 16:56
@bdbch bdbch changed the base branch from main to develop April 17, 2025 16:56
Copy link

pkg-pr-new bot commented Apr 17, 2025

Open in StackBlitz

@tiptap/core

npm i https://pkg.pr.new/@tiptap/core@6234

@tiptap/extension-bold

npm i https://pkg.pr.new/@tiptap/extension-bold@6234

@tiptap/extension-blockquote

npm i https://pkg.pr.new/@tiptap/extension-blockquote@6234

@tiptap/extension-bubble-menu

npm i https://pkg.pr.new/@tiptap/extension-bubble-menu@6234

@tiptap/extension-bullet-list

npm i https://pkg.pr.new/@tiptap/extension-bullet-list@6234

@tiptap/extension-character-count

npm i https://pkg.pr.new/@tiptap/extension-character-count@6234

@tiptap/extension-code

npm i https://pkg.pr.new/@tiptap/extension-code@6234

@tiptap/extension-code-block

npm i https://pkg.pr.new/@tiptap/extension-code-block@6234

@tiptap/extension-code-block-lowlight

npm i https://pkg.pr.new/@tiptap/extension-code-block-lowlight@6234

@tiptap/extension-collaboration

npm i https://pkg.pr.new/@tiptap/extension-collaboration@6234

@tiptap/extension-collaboration-cursor

npm i https://pkg.pr.new/@tiptap/extension-collaboration-cursor@6234

@tiptap/extension-color

npm i https://pkg.pr.new/@tiptap/extension-color@6234

@tiptap/extension-document

npm i https://pkg.pr.new/@tiptap/extension-document@6234

@tiptap/extension-floating-menu

npm i https://pkg.pr.new/@tiptap/extension-floating-menu@6234

@tiptap/extension-focus

npm i https://pkg.pr.new/@tiptap/extension-focus@6234

@tiptap/extension-dropcursor

npm i https://pkg.pr.new/@tiptap/extension-dropcursor@6234

@tiptap/extension-font-family

npm i https://pkg.pr.new/@tiptap/extension-font-family@6234

@tiptap/extension-gapcursor

npm i https://pkg.pr.new/@tiptap/extension-gapcursor@6234

@tiptap/extension-hard-break

npm i https://pkg.pr.new/@tiptap/extension-hard-break@6234

@tiptap/extension-heading

npm i https://pkg.pr.new/@tiptap/extension-heading@6234

@tiptap/extension-highlight

npm i https://pkg.pr.new/@tiptap/extension-highlight@6234

@tiptap/extension-history

npm i https://pkg.pr.new/@tiptap/extension-history@6234

@tiptap/extension-horizontal-rule

npm i https://pkg.pr.new/@tiptap/extension-horizontal-rule@6234

@tiptap/extension-image

npm i https://pkg.pr.new/@tiptap/extension-image@6234

@tiptap/extension-italic

npm i https://pkg.pr.new/@tiptap/extension-italic@6234

@tiptap/extension-link

npm i https://pkg.pr.new/@tiptap/extension-link@6234

@tiptap/extension-list-item

npm i https://pkg.pr.new/@tiptap/extension-list-item@6234

@tiptap/extension-list-keymap

npm i https://pkg.pr.new/@tiptap/extension-list-keymap@6234

@tiptap/extension-mention

npm i https://pkg.pr.new/@tiptap/extension-mention@6234

@tiptap/extension-ordered-list

npm i https://pkg.pr.new/@tiptap/extension-ordered-list@6234

@tiptap/extension-paragraph

npm i https://pkg.pr.new/@tiptap/extension-paragraph@6234

@tiptap/extension-placeholder

npm i https://pkg.pr.new/@tiptap/extension-placeholder@6234

@tiptap/extension-strike

npm i https://pkg.pr.new/@tiptap/extension-strike@6234

@tiptap/extension-subscript

npm i https://pkg.pr.new/@tiptap/extension-subscript@6234

@tiptap/extension-superscript

npm i https://pkg.pr.new/@tiptap/extension-superscript@6234

@tiptap/extension-table

npm i https://pkg.pr.new/@tiptap/extension-table@6234

@tiptap/extension-table-cell

npm i https://pkg.pr.new/@tiptap/extension-table-cell@6234

@tiptap/extension-table-header

npm i https://pkg.pr.new/@tiptap/extension-table-header@6234

@tiptap/extension-table-row

npm i https://pkg.pr.new/@tiptap/extension-table-row@6234

@tiptap/extension-task-item

npm i https://pkg.pr.new/@tiptap/extension-task-item@6234

@tiptap/extension-task-list

npm i https://pkg.pr.new/@tiptap/extension-task-list@6234

@tiptap/extension-text

npm i https://pkg.pr.new/@tiptap/extension-text@6234

@tiptap/extension-text-align

npm i https://pkg.pr.new/@tiptap/extension-text-align@6234

@tiptap/extension-text-style

npm i https://pkg.pr.new/@tiptap/extension-text-style@6234

@tiptap/extension-typography

npm i https://pkg.pr.new/@tiptap/extension-typography@6234

@tiptap/extension-underline

npm i https://pkg.pr.new/@tiptap/extension-underline@6234

@tiptap/extension-youtube

npm i https://pkg.pr.new/@tiptap/extension-youtube@6234

@tiptap/html

npm i https://pkg.pr.new/@tiptap/html@6234

@tiptap/react

npm i https://pkg.pr.new/@tiptap/react@6234

@tiptap/pm

npm i https://pkg.pr.new/@tiptap/pm@6234

@tiptap/starter-kit

npm i https://pkg.pr.new/@tiptap/starter-kit@6234

@tiptap/suggestion

npm i https://pkg.pr.new/@tiptap/suggestion@6234

@tiptap/vue-2

npm i https://pkg.pr.new/@tiptap/vue-2@6234

@tiptap/vue-3

npm i https://pkg.pr.new/@tiptap/vue-3@6234

commit: b337825

@arnaugomez arnaugomez requested a review from Copilot April 17, 2025 21:56
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the YouTube embed URL generation, adding support for start timestamps and fixing embed issues for Shorts and Live URLs.

  • Refactors URL processing by using the native URL object
  • Converts various timestamp formats to the standardized "start" parameter
  • Fixes embed issues for Shorts and Live YouTube URLs

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/extension-youtube/src/utils.ts Refactors embed URL construction and parameter mapping for YouTube URLs
.changeset/clever-hats-count.md Updates changeset metadata to reflect the PR changes


if (params.length) {
outputUrl += `${matches[1] === 'v' ? '?' : '&'}${params.join('&')}`
embedUrl.searchParams.set('rel', rel.toString())
Copy link
Preview

Copilot AI Apr 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting 'rel' without first checking if it is defined could cause a runtime error when 'rel' is undefined. Consider adding a condition to set this parameter only when defined.

Copilot uses AI. Check for mistakes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 166 literally checks if rel is not undefined.

}

if (startAt) {
params.push(`start=${startAt}`)
embedUrl.searchParams.set('start', startAt.toString())
Copy link
Preview

Copilot AI Apr 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Both the URL's 't' parameter and the 'startAt' option set the 'start' query parameter, which may lead to unintended behavior if both are provided. Consider clarifying which parameter should take precedence or add a check to avoid conflict.

Copilot uses AI. Check for mistakes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This startAt here is custom set by the developer. This must take precedence over t or start params retrieved from the URL. And searchParams.set will set a given param if not already. This code already represents the intended behaviour.

@purfectliterature
Copy link
Author

Didn't expect I'll get a review from AI, but doesn't seem like it understands the subtleties of a(n already) correct code 😆

@arnaugomez Back to you. Let me know if there are changes requested!

if (!matches || !matches[2]) {
return null
if (urlObject.searchParams.has('t')) {
embedUrl.searchParams.set('start', urlObject.searchParams.get('t')!.replaceAll('s', ''))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactoring of the URL building should ideally be done in a separate PR.

@@ -34,6 +34,28 @@ export const getYoutubeEmbedUrl = (nocookie?: boolean, isPlaylist?:boolean) => {
return nocookie ? 'https://www.youtube-nocookie.com/embed/' : 'https://www.youtube.com/embed/'
}

const getYoutubeVideoOrPlaylistId = (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to add some tests as a lot of code has been changed.

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.

[Bug]: Youtube Extension: "https://www.youtube.com/live/[id]" cannot be embedded
2 participants