In my Google Chrome extension content script I have the following:
jQuery(document).ready(function() {
var player = document.getElementById('player');
console.log(player);
console.log(document);
});
I'm running it on any Hulu video, which has the following embed with id='player'
<embed id=player type=application/x-shockwave-flash src=/site-player/playerwrapper.swf?cb=e80c477cL width=100% height=428 style=z-index:10; name=player quality=high allowscriptaccess=always allowfullscreen=true bgcolor=#000000 flashvars=bitrate=700000&user_id=-1&startLoadWrapperTime=1299572732904&overrideBrand=&referrer=http://www.hulu.com/watch/20338/saturday-night-live-steve-carell-monologue#continuous_play=on&continuous_play_on=true&sortBy=&initMode=4&modes=4&content_id=7751491&cb=2011-3-8-8&v=3>
For example, the following link http://www.hulu.com/watch/20337/saturday-night-live-snl-digital-short-the-japanese-office
But when the script is run, console.log(player) returns null. However, console.log(document) returns the proper document object.
Even if I try var player = Document.prototype.getElementById.apply(document, ['player']);
I still get null.
The funny thing is, if I try it from the Chrome JavaScript Console, it works fine, I get the proper <embed>
printed to console.
Any ideas why this isn't working in my content script?
UPDATE:
As requested, here are the complete contents of my chrome extension folder:
manifest.json:
{
name: gebidtest,
version: 1,
permissions: [
http://*/*,
https://*/*
],
content_scripts: [{
matches: [http://*/*],
js: [jquery-1.5.1.min.js,app.js]
}]
}
app.js:
jQuery(document).ready( function() {
var player = document.getElementById('player');
console.log(player);
console.log(document);
});
jquery-1.5.1.min.js: I just downloaded it
I'm using Chrome version 10.0.648.127
on a Mac, but I also tried it on a PC with the same results