Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SecurityError when accessing an iframe of same origin #4533

Closed
danielschwartz85 opened this issue Jun 20, 2019 · 6 comments
Closed

SecurityError when accessing an iframe of same origin #4533

danielschwartz85 opened this issue Jun 20, 2019 · 6 comments

Comments

@danielschwartz85
Copy link

danielschwartz85 commented Jun 20, 2019

Current behavior:

When getting an iframe of same origin and accessing it's contentDocuemnt this error is thrown:

SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "https://www.facebook.com" from accessing a cross-origin frame.

(perhaps related to #3685 ?)

Desired behavior:

Not get the error if the iframe is of the same origin

Steps to reproduce:

  1. See this repo:
    https://github.com/danielschwartz85/cypress-issue-example
  2. Or run:
const url = 'https://www.facebook.com';
const testName = url;

describe('Hello world', () => {
  it('works', () => {
    cy.visit(url);
    cy.document().then(doc => { 
        console.log('Frame url:', doc.getElementById('captcha-recaptcha').src, 'Site url', window.location.href)
        doc.getElementById('captcha-recaptcha').contentDocument // This throws exception
    })
  });
});

Versions

Cypress 3.1.5
Ubuntu 18.04.2 LTS

Thanks.

@jennifer-shehane
Copy link
Member

jennifer-shehane commented Jun 21, 2019

I'm not able to reproduce this behavior with the provided code.

The provided repo - did you not provide the branch this code is on? The master code doesn't look relevant to this issue.

Ran on Mac, Cypress 3.1.5.

Please provide all information pertaining to config, proxy, setup, plugins, etc.

Screen Shot 2019-06-21 at 2 49 16 PM

I'm not exactly sure what you are testing, but I see you are getting a 'captcha-recaptcha' element. We do not support testing captcha as it is designed to specifically avoid being automated.

@danielschwartz85
Copy link
Author

danielschwartz85 commented Jun 23, 2019

@jennifer-shehane sorry forgot to push the test file to the repo. (now pushed).

Regarding the config, etc not sure what I can add since I have no proxy, no plugin and using the default cypress config.
(Using electron 61 in UI mode)

Note that this isn't directly related to captcha since I'm just accessing the iframe's contentDocument (this also happens to me in other sites iframes..)

@danielschwartz85
Copy link
Author

btw if I open the console in the "Your App" frame and access frame's contentDocument I also get this error.

The wired thing is I'm getting this error when getting the frame with document.getElementById
but when getting the frame with document.getElementsByTagName I'm not getting the error..
Not sure what i'm missing..

cyyy

@jennifer-shehane
Copy link
Member

jennifer-shehane commented Jun 26, 2019

Ok, I am able to reproduce this in Electron 61 (Chrome 61) - that was the key information missing. This is due to some differences between Chrome 61 and the current version. We're updating Electron in an upcoming version: #4270

You can turn off this error by setting chromeWebSecurity: false in your config. https://on.cypress.io/web-security

@danielschwartz85
Copy link
Author

Thanks !

@jennifer-shehane
Copy link
Member

Electron has been upgraded to 7.1.10 as of Cypress 3.8.3 and should be resolved without the workaround.

@cypress-io cypress-io locked as resolved and limited conversation to collaborators Jan 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants