I am creating my own app using cefsharp and using ExecuteScriptAsync to send javascript to the website being viewed. However, I ran into the problem where the element I need to work with is nested within an iframe which is nested in another iframe.
I tried doing the following:
var firstIframe = document.querySelector(“iframe[title=’First Iframe’]”);
var firstIframeWindow = firstIframe.contentWindow;
var secondIframe = firstIframeWindow.document.querySelector(‘iframe[title=”Second Iframe”]’);
example of error
That gets blocked by cross origin due to the iframe coming from a different domain. At first I thought I could get around this by messing with CORS. Seeing as this error presents itself in chrome too, I tried all kinds of options of disabling CORS protection. Even with –disable-web-security argument and verifying CORS is letting everything through using https://webbrowsertools.com/test-cors/ I decided to try attacking this a different away.
I noticed in chrome devtools, you can select the iframe from a dropdown to change the javascript console context. Hey doing so, I can select the iframe I need to interact with and send the javascript code and interact with the DOM element. However, I am too much of a newbie to know how to tell cefsharp which iframe to send the javascript using ExecuteScriptAsync. HELP!!!
Example of devtools selecting iframe
I am 100% open to ideas. Ether fixing the cross origin error or to a method of telling cefsharp which iframe to ‘focus’ or whatever you want to call it for selecting the iframe to send the javascript to.