v86 icon indicating copy to clipboard operation
v86 copied to clipboard

[BUG?] Unable to embed V86

Open Keyboard1000n17 opened this issue 10 months ago • 5 comments

I'm trying to embed V86 in a website, but I can't get it to work. For some reason, i get the following error:

libv86.js:22 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'style')
    at wa.set_mode (libv86.js:22:407)
    at wa.init (libv86.js:17:319)
    at new wa (libv86.js:28:45)
    at M.continue_init (libv86.js:314:181)
    at libv86.js:308:289
set_mode @ libv86.js:22
init @ libv86.js:17
wa @ libv86.js:28
M.continue_init @ libv86.js:314
(anonymous) @ libv86.js:308
Promise.then
M @ libv86.js:308
(anonymous) @ Windows_1.01.html:119

I would try to figure out the problem, but I don't know what any of the variables in the JavaScript do, speaking of which, it errors here:

        this.set_mode = function(w) {
            u = w ? 1 : a.use_graphical_text ? 2 : 0;
            0 === u ? (l.style.display = "block",
            g.style.display = "none") : (l.style.display = "none",
            g.style.display = "block",
            2 === u && y && y.fill(1))
        }
        ;

It will likely help if I put the HTML here:

<html><head>
  <meta name="viewport" charset="utf-8" content="width=device-width, initial-scale=1.0">
  <title>Windows 1.01 Demo - OSPedia</title>
  <link rel="stylesheet" href="/pagefind/pagefind-ui.css">
  <link href="/global/stylesheets/fluent-ui-light.css" rel="stylesheet" id="setSs">
  
  <script src="/pagefind/pagefind-ui.js"></script>
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="">
  <link href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300..800;1,300..800&amp;display=swap" rel="stylesheet">
  <link rel="icon" href="/global/OSPedia-favicon.svg">
<script type="module" integrity="sha512-I1nWw2KfQnK/t/zOlALFhLrZA1yzsCzBl7DxamXdg/QF7kq+O4sYBZLl0DFCE7vP2ixPccL/k0/oqvhyDB73zQ==" src="/.11ty/reload-client.js"></script></head>





<body>

  <nav>
  <img src="/global/OSPedia-logo.svg" alt="logo" height="70%">
  <img src="/global/OSPedia-favicon.svg" alt="logo" height="70%">
  <div id="search"><div class="pagefind-ui svelte-e9gkc3 pagefind-ui--reset"><form class="pagefind-ui__form svelte-e9gkc3" role="search" aria-label="Search this site" action="javascript:void(0);"><input class="pagefind-ui__search-input svelte-e9gkc3" type="text" placeholder="Search" title="Search" autocapitalize="none" enterkeyhint="search"> <button class="pagefind-ui__search-clear svelte-e9gkc3 pagefind-ui__suppressed">Clear</button> <div class="pagefind-ui__drawer svelte-e9gkc3 pagefind-ui__hidden"> </div></form></div></div>
  <img src="/global/Images/light-dark-mode-button.png" alt="toggle dark mode" class="dark-mode-toggle">
  <ul>
    <li class="nav"><a href="/index.html" class="nav">Home</a></li>
    <li class="nav"><a href="/WinPedia/index.html">WinPedia</a></li>
    <li class="nav"><a href="/MacPedia/index.html">MacPedia</a></li>
    <li class="nav">
      <a href="/about.html" class="nav">About</a>
    </li>
  </ul>
  <img src="/global/Images/hamburger.svg" class="hamburger-menu-icon" alt="Open hamburger menu">
</nav>
<div class="hamburger-menu">
  <img src="/global/Images/close.png" class="hamburger-menu-close" alt="Close hamburger menu">
  <ul>
    <li class="nav"><a href="/index.html" class="nav">Home</a></li>
    <li class="nav"><a href="/WinPedia/index.html">WinPedia</a></li>
    <li class="nav"><a href="/MacPedia/index.html">MacPedia</a></li>
    <li class="nav">
      <a href="/about.html" class="nav">About</a>
    </li>
  </ul>
  <img src="/global/OSPedia-logo.svg" alt="logo" class="hamburger-menu-logo">
</div>
<div class="hamburger-menu-blur"></div>

  <div class="wrapper">
        <aside class="tree">
<!-- links, ignore -->
      </aside>
    <main style="color: black">
      <div class="content">
        
        <h1 id="heading">Windows 1.01 Demo</h1>        
<div class="screen" style="height: 400px">
  <canvas style="display: none"></canvas>
</div>
<script src="./libv86.js"></script>
<script>
  var emulator = new V86({
    screen_container: document.querySelector(".screen"),
    canvas: document.querySelector(".screen canvas"),
    bios: {
      url: "./seabios.bin",
    },
    vga_bios: {
      url: "./vgabios.bin",
    },
    fda: {
      url: "./images/Windows_1.01.img",
    },
    wasm_path: "./v86.wasm",
    autostart: true,
  });
</script>

      </div>
    </main>
    <div class="contents">
      <h2 id="toc">Contents</h2>
      <noscript>Enable JavaScript for the best experience!</noscript>
    </div>
  </div>
  <script src="/script.js"></script>
  <script src="/themes.js"></script>
</body></html>

And here is a screenshot, just in case:

Image

Please tell me the issue

Keyboard1000n17 avatar Jan 09 '26 16:01 Keyboard1000n17

https://github.com/copy/v86/blob/master/examples/basic.html

<div id="screen">
  <div style="white-space: pre; font: 14px monospace; line-height: 14px"></div>
  <canvas style="display: none"></canvas>
</div>

<script src="./libv86.js"></script>
<script>
  window.onload = function() {
    var emulator = new V86({
      screen_container: document.getElementById("screen"),
      // ...
    });
  }
</script>

SuperMaxusa avatar Jan 09 '26 16:01 SuperMaxusa

yeah, that worked. i think the issue was that i was using a class and not an ID. also that div wasn't there. clearer instructions would be helpful. should i add a template.html so people can easily figure out how to use it without having to infer it from the example file? thanks for the help!

Keyboard1000n17 avatar Jan 09 '26 17:01 Keyboard1000n17

should i add a template.html so people can easily figure out how to use it without having to infer it from the example file?

Probably no, at least in v86.d.ts there is a note about the structure of screen_container:

https://github.com/copy/v86/blob/11cf7dd926c5901309e7df0d34905c9a21ad4d89/v86.d.ts#L263-L266

I think a small note in this readme section would be appropriate.

SuperMaxusa avatar Jan 09 '26 17:01 SuperMaxusa

oh wait, i mean i guess that would do. a template.html would be overkill i guess

Keyboard1000n17 avatar Jan 09 '26 17:01 Keyboard1000n17

I think a better fix would be that v86 reads the contents and if there isn't a canvas and/or div element it creates them.

copy avatar Jan 26 '26 15:01 copy