Give Chrome Extension Access To Iframe Contents
Solution 1:
From the description here and chrome extension related questions you asked these days, I'd like to suggest you learn more from Official Guide, since it seems you are confused by Event page and content scripts ( you should know all_frames only apply to content scripts).
Take a look at Same-origin Policy and you should know Chrome extension doesn't allow you to access contentDocument of the iframe.
Since your purpose is to extract the #content part from youtube then append that to your canvas in new tab page, why not
- just send a ajax request to youtube
- parse the returned html response and extract the #content part
- then append it to canvas
The code looks like:
Manifest.json
{"name":"Your extension name","manifest_version":2,"version":"1.0","chrome_url_overrides":{"newtab":"newtab.html"},"permissions":["https://www.youtube.com/feed/subscriptions/*"]}
newtab.html
<!DOCTYPE html><html><head></head><body><divid="canvas"></div><scripttype="text/javascript"src="jquery.js"></script><scripttype="text/javascript"src="script.js"></script></body></html>
script.js
$.post("https://www.youtube.com/feed/subscriptions", function(html) {
$(html).find("#content").appendTo('#canvas');
});
Please be aware that the original image src in youtube page looks like src="//..."
, you should add the right domain before //
in your chrome extension. And youtube has many scripts to load, you also need to deal with that part of logic.
Last by not least, I think the best way is to find some public 3rd party api from youtube, I didn't use it but it seems Youtube | Google Developer may help.
Post a Comment for "Give Chrome Extension Access To Iframe Contents"