Showing a YouTube video in a Google Chrome extension

安稳与你 提交于 2019-12-11 12:07:55

问题


I would like to embed a YouTube player onto a page and show it to a user. If a foreground popup is used to host the player then, when the popup loses focus, the player is destroyed because the entire popup is removed.

I was hoping to use webKitNotifications.createHTMLNotification() and embed a player inside of an HTML Notification, but the spec has since been deprecated.

Just curious if anyone has any really crafty ideas on how to achieve this? I suspect hosting the YouTube player on a background page is a violation of YouTube's Terms of Service.

Looking through the dev. channel APIs:

  • http://developer.chrome.com/extensions/notifications.html - Too restrictive compared to HTML Notification. Doesn't look like I can embed a YouTube player inside one of these guys.

and... that's really about it.

Advice appreciated. Thanks.


回答1:


You can simply have an HTML file in your extension for your page, for instance video.html, list it in your manifest under web_accesible_resources, and show it using:

chrome.tabs.create({url: chrome.extension.getURL('video.html')});

Inside your page you can use whatever method you want to embed the YouTube player.



来源:https://stackoverflow.com/questions/18990317/showing-a-youtube-video-in-a-google-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!