puffinsoft / jscanify

Open-source Javascript mobile document scanner.
https://puffinsoft.github.io/jscanify/
MIT License
949 stars 52 forks source link

Bug: constructor does not work in browser environment #5

Closed InnigerM closed 1 year ago

InnigerM commented 1 year ago

When attempting to create a scanner object in browser environment following error is thrown: Uncaught (in promise) TypeError: Cannot set property document of #<Window> which has only a getter at installDOM (jscanify-node.js:9:10) at new jscanify (jscanify-node.js:30:5) at scanner.svelte:11:9 at run (index.mjs:20:12) at Array.map (<anonymous>) at index.mjs:2101:58 at flush (index.mjs:1329:17) at init (index.mjs:2197:9) at new Root (root.svelte:20:25) at createProxiedComponent (svelte-hooks.js?v=6abbeb80:341:9)

Chrome Dev version: 115.0.5762.4 (Official Build) dev (arm64) Used stack: Vite + React

Full example: https://codesandbox.io/p/sandbox/dreamy-breeze-wjwo7h

ColonelParrot commented 1 year ago

Thanks for the report! I've taken a look at it, and it appears to be an issue with React compatibility (hence marked as enhancement). I have not worked on supporting React with jscanify yet. For now, you may have to import jscanify through your index.html.

InnigerM commented 1 year ago

Might be, do you have a working test for any browser environment? Tested SvelteKit as well and that didn't work either. Tried importing the scripts through index.html as well for both projects, but that threw the exact same error.

ColonelParrot commented 1 year ago

The demo on the home page uses jscanify. This Codesandbox shows how it works on Node

InnigerM commented 1 year ago

Perfect, thanks! Have a working example now through including the jscanify script inside index.html and manually loading OpenCV as you did in the example script.

ColonelParrot commented 1 year ago

That's great to hear! Would you mind creating a demo to showcase how you did it? It would be a very helpful reference for other developers :) (perfectly fine if you don't wish)

InnigerM commented 1 year ago

Sure, happy to help! Created a small repo which more or less recreates the functionality from your demo page just in React. Feel free to use the code inside your repo as well. GitHub Code Sandbox