basic-auth.html 531 B

123456789101112131415161718192021
  1. <html>
  2. <body>
  3. <script type="text/javascript" charset="utf-8">
  4. const { ipcRenderer } = require('electron');
  5. const url = new URL(location.href);
  6. const port = url.searchParams.get('port');
  7. (async () => {
  8. try {
  9. const response = await fetch(`http://127.0.0.1:${port}`, {
  10. headers: {
  11. 'Authorization': `Basic ${btoa('test:test')}`
  12. }
  13. });
  14. ipcRenderer.sendToHost(await response.text());
  15. } catch (error) {
  16. ipcRenderer.sendToHost(error);
  17. }
  18. })();
  19. </script>
  20. </body>
  21. </html>