0

While starting to sort my js files in a recent Electron project I stopped being able to webview.executeJavascript webview being a variable that is a querySelector on my webview.

I tried testing to see if it getting the webview from the DOM and it is, all I did was move the code that worked perfectly into a module and now executeJavascript Is no longer a function.

If anybody knows the reason or has a clue whats wrong that'd be helpful!

2
  • 1
    Is it possible you could include the code of your module and if possible the code before it stopped working? Commented Sep 8, 2019 at 11:59
  • pastebin.com/TukHmV30 And the module was simply loaded with var bar = require('./file.js') Commented Sep 8, 2019 at 12:02

3 Answers 3

2

I somehow missed the fact that you can't use webview.executeJavascript() the second the Javascript has loaded and needs to wait a bit... It works now.

Sign up to request clarification or add additional context in comments.

Comments

1

Maybe the webview was not enabled?

By default the webview tag is disabled in Electron >= 5. You need to enable the tag by setting the webviewTag webPreferences option when constructing your BrowserWindow.

const w = new BrowserWindow({
  webPreferences: {
    webviewTag: true
  }
})

Source: https://github.com/electron/electron/blob/master/docs/api/breaking-changes.md#new-browserwindow-webpreferences-

Comments

1

Have you tried executeJavaScript with a capital S ?

Documentation : https://www.electronjs.org/docs/api/webview-tag#webviewexecutejavascriptcode-usergesture

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.