私はビデオの現在の時間を知ることに依存している、 youtube.com '私はdocument.getElementById('movie_player').getCurrentTime()
がこれを返す必要があることを、原則的に、知っているが、ページに注入コンテンツスクリプトでこれを呼び出すと生成:youtube.comでyoutube.comの現在の時間を取得してください(例:document.getElementById( 'movie_player')。getCurrentTime())
Uncaught TypeError: document.getElementById('movie_player').getCurrentTime is not a function(…)
私はクロームコンソールでコマンドを実行し、適切な戻り値を取得することができています。
これは重複した質問として表示される前に、私は「youtube.com」でこれを行うことを話していることを指摘したいと思います。私は特別な動作を期待する必要があるかどうかはわかりませんが、これは間違いなく私がstackoverflowで見つけた他の質問とは異なるコンテキストです。
以下は、この問題を再現するための最も簡単なコードです。それを機能させるには、load this as an unpacked extensionが必要です。次に、YouTubeのビデオに移動します。拡張子アイコンをクリックし、[テスト開始]ボタンをクリックします。また、コンソールを開いていることを確認してください(F12)。
このメソッドを動作させる方法や、必要な情報を得る方法を提案してくれてありがとうございます(たとえば、私は時間の値でシェアを得ることに目を向けましたが、それを理解できませんでした)。最後の手段として、YouTubeのプレーヤーを自分のiframeに置き換えてその方法を検討しています。
popup.html
<!doctype html>
<html>
<head>
<title>Getting Started Extension's Popup</title>
<script src='popup.js'></script>
</head>
<body>
<input type='button' id='start' value='Start The Test'></input>
<p id="messages"></p>
<p id="result"></p>
</body>
</html>
popup.js
// Add listener for start button
document.addEventListener('DOMContentLoaded', function() {
document.getElementById("start").addEventListener('click', process_video);
});
function process_video() {
chrome.tabs.executeScript(null, {file: 'test.js'});
}
test.js
player = document.getElementById('movie_player');
console.log(player);
console.log(player.getCurrentTime()); // ERROR IN QUESTION IS PRODUCED WITH THIS COMMAND
manifest.jsonを
{
"manifest_version": 2,
"name": "It's a placeholder",
"description": "This is only a test",
"version": "1.0",
"browser_action": {
"default_popup": "popup.html",
"default_title": "My Test"
},
"permissions": [
"activeTab",
"http://localhost/*",
"https://www.youtube.com/*"
]
}
あなたはCURRENTTIMEプロパティを試してみましたか? http://www.w3schools.com/TAGs/av_prop_currenttime.aspを参照してください –
私のテストスクリプトで動作するようです!私は仮回答を掲示します。本当にありがとう! – austinmilt