I have an electron app with a webview in the page loaded in my BrowserWindow. This website is emitting in some occasion Confirm or Alert but electron is showing them. Is there any way of modifying this behavior for example in the code I inject on the website page?
-
There is a big error from my side it should be Electron Is not SHOWING THEM – Alain BUFERNE Nov 29 '17 at 16:11
2 Answers
You can try to inject code like:
window.confirm = function (msg) {
console.log('always agree:', msg);
return true;
};
To override the confirm event. You can do the same for alert or what you prefer.
Sadly, I think you can't manage the event from Electron: request
Update
After the modify to the question, you want to SHOW alert and similar. So, you can follow this answer:
prompt
, confirm
and alert
are functions which blocks the execution thread of the script until a user input and that's the reason electron team didn't supported it. Instead you can use some third party package for the same reason.
Here are some packages which provides this functionality in async way
https://www.npmjs.com/package/smalltalk

- 696
- 8
- 25
-
My bad The Question should be Confirm or Alert but electron is NOT SHOWING them. And If I redefine the confirm function, it is well registered in the injected code but this function is never reached. – Alain BUFERNE Nov 29 '17 at 16:10
-
No, I don't want to use these popups but the website I show in the webview in some case use them but the user of my app doesn't sees them and the website look like crashed but just waiting for click on something not shown – Alain BUFERNE Nov 30 '17 at 13:53
-
You can only hijack this from javascript (like the original answer) and then open a popup in other way, managing the response. If you can't modify the page in the webview, it can be hard :) – emish89 Nov 30 '17 at 14:52
As the website is alerting when the user want to quit the page after modifying some data. The website is using onbeforeunload
attibute of the document.body.
So I'm writing a piece of code using MutationObserver
to listen in the injected code of the webview at this attibute and reset it myself plus using the Electron Confirm
located in override.js
to warn the use. Not finish yet because of others problems but it is the way...

- 2,016
- 3
- 26
- 37