b-fuze / deno-dom

Browser DOM & HTML parser in Deno
https://jsr.io/@b-fuze/deno-dom
MIT License
423 stars 47 forks source link

error: Uncaught (in promise) RuntimeError: memory access out of bounds #148

Closed kemiller closed 9 months ago

kemiller commented 1 year ago

Trying to do a pretty simple HTML parse, and get WASM error:

deno run --allow-all scrape.ts
error: Uncaught (in promise) RuntimeError: memory access out of bounds
    at <anonymous> (wasm://wasm/002085c6:1:160314)
    at <anonymous> (wasm://wasm/002085c6:1:259412)
    at <anonymous> (wasm://wasm/002085c6:1:258885)
    at passStringToWasm0 (https://deno.land/x/deno_dom@v0.1.40/build/deno-wasm/deno-wasm.js:57:11)
    at parse (https://deno.land/x/deno_dom@v0.1.40/build/deno-wasm/deno-wasm.js:96:16)
    at nodesFromString (https://deno.land/x/deno_dom@v0.1.40/src/deserialize.ts:10:29)
    at DOMParser.parseFromString (https://deno.land/x/deno_dom@v0.1.40/src/dom/dom-parser.ts:24:21)
    at file:///Users/ken/Code/scraper/scrape.ts:21:29
    at eventLoopTick (ext:core/01_core.js:197:13)

Offending line is just this:

const doc = new DOMParser().parseFromString(page.content(), "text/html"); // page from puppeteer

Is there anything special I should be doing differently or is this a bug?

b-fuze commented 1 year ago

Can you share the HTML that caused that error

Robert-Ernst commented 3 months ago

I got the same issue

import { DOMParser } from "jsr:@b-fuze/deno-dom";

let text = response.text();
const response = await fetch("https://golem.de")
const doc = new DOMParser().parseFromString(text, "text/html")

error: Uncaught (in promise) RuntimeError: memory access out of bounds at dlmalloc::dlmalloc::Chunk::size::hc1c6ee1862ed3f63 (wasm://wasm/00257616:1:269921) at rdl_realloc (wasm://wasm/00257616:1:156715) at __rust_realloc (wasm://wasm/00257616:1:268867) at wbindgen_realloc (wasm://wasm/00257616:1:267789) at passStringToWasm0 (https://jsr.io/@b-fuze/deno-dom/0.1.47/build/deno-wasm/deno-wasm.js:57:11) at parse (https://jsr.io/@b-fuze/deno-dom/0.1.47/build/deno-wasm/deno-wasm.js:96:16) at nodesFromString (https://jsr.io/@b-fuze/deno-dom/0.1.47/src/deserialize.ts:10:29) at DOMParser.parseFromString (https://jsr.io/@b-fuze/deno-dom/0.1.47/src/dom/dom-parser.ts:24:21)

b-fuze commented 2 months ago

@Robert-Ernst your code looks a bit incorrect so I fixed it and couldn't reproduce, it works for me:

import { DOMParser } from "jsr:@b-fuze/deno-dom";

const response = await fetch("https://golem.de")
const text = await response.text();
const doc = new DOMParser().parseFromString(text, "text/html")!;
console.log(doc.querySelectorAll("*").length);
console.log(doc.documentElement?.outerHTML);

what platform are you using and which version of Deno?