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

[Bug]: <webView>.methods not available in preload script #41814

Closed
3 tasks done
charlie632 opened this issue Apr 9, 2024 · 5 comments
Closed
3 tasks done

[Bug]: <webView>.methods not available in preload script #41814

charlie632 opened this issue Apr 9, 2024 · 5 comments

Comments

@charlie632
Copy link

charlie632 commented Apr 9, 2024

Preflight Checklist

Electron Version

29.2.0

What operating system are you using?

macOS

Operating System Version

14.1.1 (23B81)

What arch are you using?

arm64 (including Apple Silicon)

Last Known Working Electron version

No response

Expected Behavior

I have this in my index.html:

      <webview
        id="foo"
        src="https://www.github.com/"
        style="display: inline-flex; width: 640px; height: 480px"></webview>

Calling webView from the preload script should work

  const webview = document.getElementById('foo');

  webview.addEventListener('dom-ready', function (e) {
    console.log('webview dom-ready', webview.getWebContentsId);
  });

Actual Behavior

The callback is called, but the webview.getWebContentsId is undefined. All methods described here: https://www.electronjs.org/docs/latest/api/webview-tag#methods are undefined.

If the same is run on the renderer process it works as expected.

Testcase Gist URL

https://gist.github.com/charlie632/406270a2f91c0aafc5472d52d4ecea32

Additional Information

No response

@charlie632
Copy link
Author

@codebytere codebytere added the blocked/need-repro Needs a test case to reproduce the bug label Apr 10, 2024
@electron-issue-triage
Copy link

Hello @charlie632. Thanks for reporting this and helping to make Electron better!

Would it be possible for you to make a standalone testcase with only the code necessary to reproduce the issue? For example, Electron Fiddle is a great tool for making small test cases and makes it easy to publish your test case to a gist that Electron maintainers can use.

Stand-alone test cases make fixing issues go more smoothly: it ensure everyone's looking at the same issue, it removes all unnecessary variables from the equation, and it can also provide the basis for automated regression tests.

Now adding the blocked/need-repro Needs a test case to reproduce the bug label for this reason. After you make a test case, please link to it in a followup comment. This issue will be closed in 10 days if the above is not addressed.

@charlie632
Copy link
Author

@electron-issue-triage electron-issue-triage bot removed the blocked/need-repro Needs a test case to reproduce the bug label Apr 10, 2024
@MaximKalinin
Copy link

Hello!
I see that in the example above they disable contextIsolation: false for the browser window instance. If I add it to your gist, it also works.

https://github.com/ddupont808/GPT-4V-Act/blob/7b0cbfd561e5d4e2f524b299559e4fdbc067fccd/main.js#L82
image

@georgexu99
Copy link
Contributor

georgexu99 commented Apr 16, 2024

Thanks for submitting this issue! I believe this is intended behaviour and that you need to either 1) expose the views api via contextBridge, or 2) (not recommended) turn off contextIsolation (see above comment). Feel free to re-open if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: 👀 Unsorted Items
Development

No branches or pull requests

4 participants