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

webview.executeScript wrong context #6299

Closed
dmx-patrick opened this issue Nov 20, 2017 · 2 comments
Closed

webview.executeScript wrong context #6299

dmx-patrick opened this issue Nov 20, 2017 · 2 comments

Comments

@dmx-patrick
Copy link

dmx-patrick commented Nov 20, 2017

NWJS Version : 0.26.6
Operating System : Windows 10

Expected behavior

I expect it to execute the script in the isolated context where my contentScripts are loaded

Actual behavior

It executes the script in the main context

How to reproduce

webview.addEventListener('loadcommit', function(e) {
  webview.addContentScripts([{
    name: 'inject',
    matches: [ '<all_urls>'],
    js: { files: ['jquery.js'] },
    run_at: 'document_end'
  }]);
});

webview.addEventListener('contentload', function(e) {
  webview.executeScript({ code: '$("body").css("background", "red")' });
});

In the isolated context you have full access to the dom and I don't want to inject my libraries directly in the guest page since they could conflict with other scripts that are loaded there. If I would like to execute directly within the guest context I would have used an iframe instead of a webview.

The default behavior was changed in version 0.26.5, related issue: #6229

@rogerwang
Copy link
Member

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.

@rogerwang
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants