Nw.js: webview.executeScript wrong context

Created on 24 Oct 2017  Â·  9Comments  Â·  Source: nwjs/nw.js

NWJS Version : 0.26.0
Operating System : macos

Expected behavior

webview.executeScript({code: 'console.log(window)'}, console.log)
should log the window object

Actual behavior

webview.executeScript({code: 'console.log(window)'}, console.log)
logs the wrong window object

How to reproduce

webview.executeScript.example.zip

P2 bug triaged

Most helpful comment

This is fixed in git and will be available in the next nightly build.

All 9 comments

I try the sample on Mac with nwjs-sdk-v0.26.0, here is my result, it returns null.

screen shot 2017-10-25 at 9 52 29 am

It's executed in the right context. It's just the issue of accessing returned window object. Will look into this.

If you execute document.body.style.backgroundColor = "red"; everything works fine.

Turns out it's executed in a isolated world on purpose by upstream: https://stackoverflow.com/a/24435983/180197

Will remove this limitation for NW app.

This is fixed in git and will be available in the next nightly build.

I have some workaround code that depends on the code being executed in the extension "isolated world" context. Is it possible, in the future, to have extra fields in the InjectDetails to determine the context?

@phiSgr yes. Please file another issue for this feature.

Will add a boolean field mainWorld in InjectDetails to control the world where the code would run. The default value would be false to keep align with upstream. Thanks.

@rogerwang are those new options already available? Or coming up in the new release?

Yes see
http://nwjs.readthedocs.io/en/nw27/References/webview%20Tag/#executescript-in-main-world

It's in 0.27 nightly and will be released with 0.27.0 in 1 or 2 days.

On Dec 6, 2017 8:26 PM, "George Petrov" notifications@github.com wrote:

@rogerwang https://github.com/rogerwang are those new options already
available? Or coming up in the new release?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/nwjs/nw.js/issues/6229#issuecomment-349624550, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAKGGRDXsBhRlnZGhfXU754Anzx_CLMXks5s9ofpgaJpZM4QFIg0
.

Was this page helpful?
0 / 5 - 0 ratings