0

I am trying to access the SVG of the blue graph inside an iFrame on this website by opening it up in a new tab.

frames = document.querySelectorAll('iframe');
var url = frames[0].src;
var tab = window.open(url, '_blank');
tab.focus();

When this code executes, all I see is a blank page. Similarly, when I right click on the SVG and select "view frame source" and remove "view-source:" from the URL, I also see a blank page. I can, however, view the HTML inside the iFrame from viewing the original website's page source. Is there any way to fix this?

I also tried extracting the HTML using

frames[0].contentWindow.document.body.innerHTML

but it gave me an error.

The target origin provided ('https://observablehq.com') does not match the recipient window's origin ('https://d3.static.observableusercontent.com').

My understanding is that JavaScript cannot extract the HTML content of cross origin frames.

My final goal is to be able to somehow download the SVG. Would there be any other way to download the SVG?

  • Declare your content script with `all_frames` so it runs **inside** this iframe and then it'll be able to access its `document` directly. – wOxxOm Feb 09 '23 at 18:48
  • `My understanding is that JavaScript cannot extract the HTML content of cross origin frames.` This is correct. `My final goal is to be able to somehow download the SVG. Would there be any other way to download the SVG?` For the reason above, no. – Rory McCrossan Feb 09 '23 at 19:28
  • Extensions can do it as described above. – wOxxOm Feb 10 '23 at 02:52

0 Answers0