spectron
spectron copied to clipboard
webContents is missing part of its API
Here, it says that app.webContents should give a handle to an Electron WebContents instance:
https://github.com/electron/spectron#webcontents
That section also links to the full webContents API, documented here: http://electron.atom.io/docs/api/web-contents/
However, when I use Spectron, I'm seeing that only a subset of the webContents API works.
For example, app.webContents.getTitle() works, but app.webContents.executeJavascript() doesn't work. session is also missing.
- Why is only a subset of the WebContents API available?
- Is there any easy way to run Javascript in the context of the renderer? In other words, an alternative to
executeJavascript
executeJavascriptis a typo. The API is actuallyexecuteJavaScript- See the answer to question 1 👍
@MarshallOfSound thanks. Wow I'm a tool
What about webContents.session ?
@dcposch Currently we are only mapping methods on the webContents object to Spectron methods.
See https://github.com/electron/spectron/blob/master/lib/api.js#L150
@kevinsawicki Should we add something like getProperty('session') to return the session object?
Should we add something like getProperty('session') to return the session object?
Yeah, would be nice to support important properties
Is there an appropriate work around for accessing properties of the webContents object?
It might also be sensible at some-point to document the fact that it only maps the methods and not the properties.
I am also in need for access to webContents.session. Are there any news on that?
If you want to clear localStorage data this works:
await app.webContents.executeJavaScript('localStorage.clear()');
app.webContents.reload();