0

I know this question has been asked here several times but I couldn't be able to find the perfect working solution.

I am trying to embed my Angular 4 application url inside the Iframe :

<html>
    <body>
        <iframe src="http://localhost:4300/login" height="200"></iframe>
    </body>
</html>

But, as soon as I open this page, I can't see my application running. I found that the issue is related to the CORS, but I could not be able to figure out the exact solution for this.

On my browser console I am getting the below error:

ERROR DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.
    at t._loadLevel (http://localhost:4300/vendor.0a81172ada1f31f3dc62.bundle.js:1:927903) 

Existing similar questions:

Link inside iframe wont work

How to open a iframe link within the same iframe?

how to resolve iframe cross domain issue

https://github.com/apollographql/apollo-client-devtools/issues/106

https://github.com/disconnectme/disconnect/issues/315

https://www.chromium.org/for-testers/bug-reporting-guidelines/uncaught-securityerror-failed-to-read-the-localstorage-property-from-window-access-is-denied-for-this-document

Iframe in Chrome error: Uncaught SecurityError: Failed to read the 'sessionStorage' property from 'Window'

Please help me on this.

Rohitesh
  • 1,514
  • 7
  • 28
  • 51

1 Answers1

0

At the risk of sounding overly simplistic, have you tried enabling third-party cookies in whatever browser you're using?

I had some issues with localStorage and an angular app inside an iframe and that ended up working.

For example, in Chrome:

https://www.chromium.org/for-testers/bug-reporting-guidelines/uncaught-securityerror-failed-to-read-the-localstorage-property-from-window-access-is-denied-for-this-document

fleadram
  • 30
  • 5
  • i don't force the use to change the setting of browser . If we can handle pragmatically then it would be great. – Rohitesh Jun 18 '18 at 16:24
  • I'd check to see if that is, in fact, the issue locally. If it is, I'd make sure your users are going to have issues. For me, I had my local settings set up that way, but have not heard a peep from any users about this issue. I think it's almost impossible to browse the web will all cookies blocked, and it shouldn't be a default browser setting. – fleadram Jun 18 '18 at 16:31
  • i am not sure but my cookie option is enable but Block third-party cookies is disabled. – Rohitesh Jun 18 '18 at 16:37
  • One more thing to try, if you are using Chrome, the top security setting for cookies reads: "Allow sites to save and read cookie data". Make sure this is enabled. If that doesn't work, then my experience is limited on this issue. Have you tried different browsers? That might at least narrow the issue a little if they are either all broken, or some of them work. – fleadram Jun 18 '18 at 16:45