0

I am trying to make a chrome extension that opens a url that prompts the user to open an external application. The chrome browser prompts the user with a confirm box(OK or Cancel). I want to disable the confirm box for that website only(for security reasons) so that it opens the application without it.

Edit: It is not exactly a confirm box. It is box that says, [Cancel] and [Open With external application].

1 Answers1

0

In the page context, you could overwrite window.confirm so that it returns true immediately, rather than opening the modal:

window.confirm = () => true;

if (confirm('OK?')) {
  console.log('Going...');
}

If the confirm modal opens immediately on pageload, make sure to have the extension run at document_start so that confirm gets overwritten immediately, rather than after a delay.

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
  • I assume OP means [disable chrome to ask for confirmation to open external application](https://superuser.com/questions/1481851/disable-chrome-to-ask-for-confirmation-to-open-external-application-everytime) rather than window.confirm. Still pretty cool – mplungjan Apr 05 '20 at 07:00
  • 1) this will work only in [page context](https://stackoverflow.com/a/9517879), 2) extensions use `document_start` spelling with an underscore. – wOxxOm Apr 05 '20 at 08:48
  • using whatsapp:// in the matches content_script does not work....is there a way around that – Harsh Kumar Gupta Apr 05 '20 at 15:51
  • even if i use "https://api.whatsapp.com/*" in "matches", it does not work. It seems that the 'opening in external application' modal box is different than a normal confirm box. – Harsh Kumar Gupta Apr 05 '20 at 16:11
  • @HarshKumarGupta You should've specified that in your question - that's *not* `window.confirm`, that's something that Javascript can't affect – CertainPerformance Apr 05 '20 at 20:00