index.html 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <!DOCTYPE html>
  2. <html lang="en-US">
  3. <head>
  4. <script>
  5. // malicious
  6. window.__TAURI_PATTERN__ = Object.freeze({pattern: "malicious"});
  7. </script>
  8. <script>
  9. // malicious defineProperty
  10. Object.defineProperty(window, "__TAURI_PATTERN__", {value: Object.freeze({pattern: "malicious"})});
  11. </script>
  12. <meta charset="UTF-8">
  13. <title>Hello Tauri!</title>
  14. <style>
  15. body {
  16. /* Add a nice colorscheme to our page and text */
  17. background-color: #222831;
  18. color: #ececec;
  19. /* Make the body tag the exact size of the window */
  20. margin: 0;
  21. height: 100vh;
  22. width: 100vw;
  23. /* Vertically and horizontally center children of the body tag */
  24. display: flex;
  25. justify-content: center;
  26. align-items: center;
  27. }
  28. div {
  29. display: flex;
  30. flex-direction: column;
  31. justify-content: center;
  32. align-items: center;
  33. }
  34. </style>
  35. <script type="text/javascript">console.log("inline", window.__TAURI_PATTERN__);</script>
  36. </head>
  37. <body>
  38. <div>
  39. <h1>Hello, Tauri!</h1>
  40. <pre><code></code></pre>
  41. <div>
  42. <button id="ping">ping</button>
  43. <span id="pong"></span></div>
  44. </div>
  45. <script>
  46. const code = document.querySelector("code");
  47. const obj = {};
  48. function updateCode(key, value) {
  49. obj[key] = value;
  50. code.innerText = JSON.stringify(obj, null, 2);
  51. }
  52. const cb = window.__TAURI__.transformCallback(v => updateCode('response', v));
  53. const error = window.__TAURI__.transformCallback(e => updateCode('response', e));
  54. window.ipc.postMessage(JSON.stringify({
  55. cmd: "ping",
  56. callback: cb,
  57. error,
  58. }));
  59. updateCode('__TAURI_PATTERN__', window.__TAURI_PATTERN__);
  60. </script>
  61. <!-- set up click handlers on our ping command button -->
  62. <script>
  63. const ping = document.querySelector("#ping")
  64. const pong = document.querySelector('#pong')
  65. ping.addEventListener("click", () => {
  66. window.__TAURI_INVOKE__("ping")
  67. .then(() => {
  68. pong.innerText = `ok: ${Date.now()}`
  69. })
  70. .catch(() => {
  71. pong.innerText = `error: ${Date.now()}`
  72. })
  73. })
  74. </script>
  75. </body>
  76. </html>