1

There is page with economic calendar.

Scenario:

  1. I am loading page in browser. For example this: http://www.dukascopy.com/swiss/english/marketwatch/calendars/eccalendar/
  2. Look through it. And if there is interesting data for me, I click button and save all html with loaded iframe-data for parsing.

The problem is that necessary data on this page loaded with iframe. I read here that chrome denies iframe access with js-injects. But I can easy access necessary tables with "inspect element" from right-click menu. Is it possible to access it without js-injects? Just like automatic "inspect DOM element" or inner HTML?

I solved this issue in pyside (python qt webkit interface) this way:

def print_content():
 res = web.page().mainFrame().childFrames()
 for i in res:
 s = i.documentElement().toOuterXml()
 print(s)

But now I want do it from chrome(chromium) extension. Is there similar functional in modern chrome(chromium)? For example:

chrome.web.page().mainFrame().childFrames() etc...

UPD:

Tried recomendation. Corrected manifest and add to content script:

chrome.runtime.sendMessage({greeting: "hello"}, function(response) {
 var res = document.querySelectorAll("iframe");
 var len = res.length;
 for (var i = 0; i < len; i++) {
 //alert(myStringArray[i]);
 console.log(res[i].contentDocument);
 //Do something
 }
 //console.log(res);

Getting this error: Error in event handler for (unknown): Error: Blocked a frame with origin "dukascopy.com"; from accessing a cross-origin frame. at chrome-extension://bgoddjjeokncninlaacmjamgkohmcecb/content.js:19:23 at extensions::messaging:323:11 at Function.target.(anonymous function) (extensions::SafeBuiltins:19:14) at Event.dispatchToListener (extensions::event_bindings:386:22) at Event.dispatch_ (extensions::event_bindings:371:27) at Event.dispatch (extensions::event_bindings:392:17) at dispatchOnDisconnect

Cœur
39k25 gold badges207 silver badges282 bronze badges
asked May 20, 2014 at 10:49
4
  • Do you need to interact with the DOM elements inside the iframe or just parse the data? If you only need to read the data in the iframes there is no need to inject into the frames. Your python code could be replaced with JS easily, for example: var res = document.querySelectorAll("iframe"); Commented May 20, 2014 at 14:23
  • try to use in content_script and flush a result to js console. It shows me some fileds and this "contentDocument: [Exception: DOMException]" OutterHTML also doesnt include builded tables of iframe. So content is not accesable? or I am mistaken somewhere? Commented May 23, 2014 at 13:22
  • ALSO LOGGED THIS: Error in event handler for (unknown): Error: Blocked a frame with origin "dukascopy.com" from accessing a cross-origin frame. at chrome-extension://bgoddjjeokncninlaacmjamgkohmcecb/content.js:19:23 at extensions::messaging:323:11 at Function.target.(anonymous function) (extensions::SafeBuiltins:19:14) at Event.dispatchToListener (extensions::event_bindings:386:22) at Event.dispatch_ (extensions::event_bindings:371:27) at Event.dispatch (extensions::event_bindings:392:17) at dispatchOnDisconnect (extensions::messaging:283:27) Commented May 23, 2014 at 13:38
  • OK, so the problem with this approach here is that the domain of the iframe and the parent page are different, so my approach will not work in this case. This approach will work for iframes that are of the same domain and protocol of the parent page (ie. it is possible to read iframe content without injection) Commented May 23, 2014 at 14:45

1 Answer 1

0

You need to inject your content script into the inner frame to access it. This is perfectly possible, it's just that the outer document's script cannot access the iframe contents.

This question covers how to do this in case of manifest-based injection.

For programmatic injection, you can pass all_frames: true in InjectDetails object for chrome.tabs.executeScript.

answered May 20, 2014 at 12:37
Sign up to request clarification or add additional context in comments.

5 Comments

I added this to manifest and this errored log as I descibed in prev question
The error indicates that you're trying to access an inner iframe from the outer page. This will not work. You need to inject a script into the inner frame and work with its content.
According to your link that is such string to execute command only in inner html. if (parent === top) { // here you can put your code that will run only inside iframe console.log(res[i].contentDocument);} But it cause the same error
p.s. the domains of iframe and parent page differs. Is you advice proper with such conditions?
Yes. Your content script settings / permissions should include the inner frame's domain.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.