check-origin.html 651 B

123456789101112131415161718192021222324252627282930313233
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>test ws connection</title>
  5. <script>
  6. const query = new URL(location.href).searchParams;
  7. async function test() {
  8. try {
  9. const port = query.get('port');
  10. const ws = new WebSocket(`ws://127.0.0.1:${port}/check-origin`);
  11. const ev = await new Promise((resolve, reject) => {
  12. ws.onmessage = resolve;
  13. ws.onclose = reject;
  14. });
  15. if (ev.data == 'file://') {
  16. document.title = 'FILE';
  17. } else if (ev.data == 'null') {
  18. document.title = 'NULL';
  19. } else {
  20. document.title = 'FAIL';
  21. }
  22. } catch (e) {
  23. document.title = 'FAIL';
  24. }
  25. }
  26. test();
  27. </script>
  28. </head>
  29. </html>