I want to send a POST
request with an Electron webview from the outer script. At the moment I just set the src
attribute to trigger a page load, which sends a GET
request:
<webview id="view">
<script>
document.getElementById('view').setAttribute('src', 'http://example.com/?foo=bar');
</script>
Is there any way to navigate the webview to a URL by sending a POST
request? Maybe a method of the webview
, instead of just hacking with the src
?
You can execute arbitrary code from within the webview context with .executeJavaScript
.
Moreover your code has access to all browser built-in apis. Easiest would be to use fetch
, with method set to post
.
In your case (provided the webview has been already loaded; for example its .src
has been set):
document.getElementById('view')
.executeJavaScript('fetch("http://example.com/?foo=bar", {method: "post"});');
Some remarks:
.src
of the webview.http:
from https:
.Now there is a new <webview>.loadURL()
method with a postData
option in the docs. I haven't used it yet but it looks exactly like what I was looking for in the past.
It seems they added it as a feature in the meantime.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With