question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No longer can access iframe contentWindow since 0.40.0

See original GitHub issue

NWJS Version : 0.41.2, bug since 0.40.0 Operating System : CentOS 7.7

Expected behavior

iframe.contentWindow should work.

Actual behavior

FAILED SecurityError: Blocked a frame with origin “chrome-extension://goedajggnemaklpbabiibhndbgcfdmoj” from accessing a cross-origin frame.

How to reproduce

Simplest NW.js app with index.html

<html><head><script>
function showLocation () {
  try {
    var location = document.querySelector("iframe").contentWindow.location.href;
  } catch (e) {
    location = `FAILED ${e}`;
  }
  document.querySelector("p").textContent = location;
}
</script></head>
<body onload="showLocation();">
<p>waiting for onload</p>
<iframe src="http://www.wikipedia.org/"></script>
</body></html>

Until NW.js 0.39.3 after loading page it shows

https://www.wikipedia.org/

This example happens to show a change of URL, from http redirected to https.

Since NW.js 0.40.0 and still in NW.js 0.41.2 after loading page it shows

SecurityError: Blocked a frame with origin “chrome-extension://goedajggnemaklpbabiibhndbgcfdmoj” from accessing a cross-origin frame.

This is supposed to work per documentation http://docs.nwjs.io/en/latest/For Users/Advanced/Security in NW.js/ where it says

you can … access to <iframe> element whose src points to remote sites

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
liuyicommented, Nov 5, 2019

I resolved ths probem, like this: 1\set package.json “chromium-args”:“–disable-web-security’”

2\ Use window.postMessage('what your want to send",“*”) instead of javscript call.

That’s all. It works!

0reactions
josh83abccommented, Nov 13, 2019

Thanks Roger for reopening the issue. As you probably found out, it doesn’t work even on 0.43.0-beta1. A big thanks for your amazing work!

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Get element from within an iFrame - Stack Overflow
var iframe = document.getElementById('iframeId'); var innerDoc = (iframe.contentDocument) ? iframe.contentDocument : iframe.contentWindow.document;.
Read more >
HTMLIFrameElement.contentWindow - Web APIs | MDN
The contentWindow property returns the Window object of an HTMLIFrameElement. You can use this Window object to access the iframe's document ...
Read more >
HTML DOM IFrame contentWindow Property - W3Schools
The contentWindow property returns the Window object generated by an iframe element (through the window object, you can access the document object and...
Read more >
Access iFrame contentWindow in Service Portal Client script
Solved: Hi there, I am using an iframe in Service portal widget to load page from another application. I have a requirement to...
Read more >
Get an element from within an iframe with JavaScript
We're no longer updating this content regularly. ... is also the possibility to access an element within a web page's iframe via Javascript....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found