Javascript Chrome扩展不提供youtube IFRAME的当前时间
我想做的是通过扩展我想得到我试过的视频的当前时间Javascript Chrome扩展不提供youtube IFRAME的当前时间,javascript,google-chrome-extension,youtube,youtube-api,html5-video,Javascript,Google Chrome Extension,Youtube,Youtube Api,Html5 Video,我想做的是通过扩展我想得到我试过的视频的当前时间 var htmlVideoPlayer = document.getElementsByTagName('video')[0]; htmlVideoPlayer.currentTime 但这是一个错误 现在看这张图片 它给了我当前时间,但我无法从我的chrome扩展访问它 它给出了CORS错误 有没有办法从其他网站获取youtube IFRAME视频的当前时间,这样我就可以在扩展中使用它 还使用此函数从我的分机获取youtube IFRAME
var htmlVideoPlayer = document.getElementsByTagName('video')[0];
htmlVideoPlayer.currentTime
但这是一个错误
现在看这张图片
它给了我当前时间,但我无法从我的chrome扩展访问它
它给出了CORS错误
有没有办法从其他网站获取youtube IFRAME视频的当前时间,这样我就可以在扩展中使用它
还使用此函数从我的分机获取youtube IFRAME视频的当前时间
这是我的script.js
setInterval(function() {
if ($('document.querySelector(".video-stream").getCurrentTime()').length) {
console.log("Video Time Exists!");
var videoTime = document.querySelector('.video-stream').getCurrentTime();
console.log(videoTime);
}
else{
console.log("waiting");
}
}, 100);
这是显而易见的
{
"manifest_version": 2,
"name":"MyExtension",
"version": "0.1",
"description": "NewExtension Coming soon",
"content_scripts":[{
"js":[
"js/jquery-3.5.1.js",
"js/script.js"
],
"run_at":"document_idle",
"matches":[
"http://*"
],
"all_frames": true
}],
"permissions":[
"tabs",
"activeTab"
]
}
您需要使用executeScript中的
“all_frames:true
或使用allFrames:true
声明内容脚本。未能在“DOMWindow”上执行“postMessage”:提供的目标源(')与收件人窗口的源(')不匹配。这就是我得到的,我们需要看到更多的代码。有关说明,请参阅。我添加了一些代码,我在content.js中尝试了这些代码,我希望获得currentTime();我的chrome扩展中的Iframe视频,我们还需要查看您如何运行/注入/声明此代码。您需要使用“所有帧”:true
声明内容脚本,或在executeScript中使用所有帧:true
。未能在“DOMWindow”上执行“postMessage”:提供的目标源(')与收件人窗口的源(')不匹配。这就是我得到的,我们需要看到更多的代码。有关说明,请参阅。我添加了一些代码,我在content.js中尝试了这些代码,我希望获得currentTime();我的chrome扩展中的Iframe视频,我们还需要了解如何运行/注入/声明此代码。