"콘텐츠 스크립트"Chrome 확장 프로그램에서 "YouTube iframe API"를 사용하고 싶습니다. 내 확장 프로그램에서 YouTube iframe API를 어떻게 사용해야합니까?Google 크롬 확장 프로그램에서 외부 자바 스크립트가 필요합니다.
Youtube iFrame API의 URL : https://www.youtube.com/iframe_api.
일반적으로 매니페스트 파일의 Google 크롬 확장에 스크립트를 포함하지만 URL의 확장자가 .js가 아니기 때문에 Chrome의 확장 프로그램 페이지에 오류가 발생합니다.
또한이 URL의 스크립트는 <script>
태그를 삽입하려고하는데, 이는 content_script 플러그인이 페이지의 javascript에 액세스 할 수 없기 때문에 작동하지 않습니다.
manifest.json을
{
...
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["main.js"],
"all_frames": true
}
]
}
main.js 내가 다른 일을해야 무엇
// Inject the script, but this won't work since content scripts can't access the page's javascript (which is where this script is injected).
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
(document.head || document.documentElement).appendChild(tag);
// Create our own player
var player;
var videoID = 'e7Px2yJA6S4';
// When the YouTube API is loaded, it calls this function.
function onYouTubeIframeAPIReady() {
player = new YT.Player('movie_player', {
height: '390',
width: '640',
videoId: videoID,
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
? 이 스크립트를 올바르게 포함하려면 어떻게해야합니까?
이 솔루션의 문제는 main.js는 여전히 inject.js로부터 분사 된 API에 대한 액세스 권한이없는 것입니다. –
@DonnyP 업데이트. 기본적으로 실행 환경으로 인해 내용 스크립트와 '