chromeless icon indicating copy to clipboard operation
chromeless copied to clipboard

Evaluating Scripts inside of iframes

Open ghost opened this issue 6 years ago • 1 comments

Hi there, I am on a team that is trying to test a website that includes an iframe to a third-party component hosted on a different server. We need to be able to detect DOM events on document elements inside this iframe but I am running into the following error:

(node:17244) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: DOMException: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame 
with origin "https://oursite.com" from accessing a cross-origin frame.

Is there a way to disable the same origin security policy in the automatically launched instance of Chrome started by Chromeless? Or would it be best just to start a local instance of Chrome with the --disable-web-security ?

Additional Details: Our code looks as follows (hosts/urls changed):

async function run() {
  const chromeless = new Chromeless()

  var extIframePresent = await chromeless.goto('https://oursite.com/ourpage')
    .wait(4000)
    .evaluate(()=>{
        var extIframe = document.getElementsByClassName('container-with-3rd-party-iframe')[0].getElementsByTagName('iframe')[0];
        extIframe = extIframe.contentDocument || extIframe.contentWindow.document;
        extIframe = extIframe.contentDocument;

        return extIframe;

    });
    console.log('extIframePresent = ', extIframePresent);
    

}

run()

ghost avatar Dec 12 '17 00:12 ghost

+1

bubakazouba avatar Jun 18 '18 21:06 bubakazouba