René's URL Explorer Experiment


Title: Illegal constructor · Issue #154 · Dynamsoft/barcode-reader-javascript · GitHub

Open Graph Title: Illegal constructor · Issue #154 · Dynamsoft/barcode-reader-javascript

X Title: Illegal constructor · Issue #154 · Dynamsoft/barcode-reader-javascript

Description: Hello, Short version: maybe I am just blind after some hours spent on that. There is an annoying "Illegal constructor" appearing and I cannot figure out why. I am trying to set up the React VideoCapture element as mentioned here. It look...

Open Graph Description: Hello, Short version: maybe I am just blind after some hours spent on that. There is an annoying "Illegal constructor" appearing and I cannot figure out why. I am trying to set up the React VideoCa...

X Description: Hello, Short version: maybe I am just blind after some hours spent on that. There is an annoying "Illegal constructor" appearing and I cannot figure out why. I am trying to set up the Rea...

Opengraph URL: https://github.com/Dynamsoft/barcode-reader-javascript/issues/154

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Illegal constructor","articleBody":"Hello,\r\n\r\nShort version: maybe I am just blind after some hours spent on that. There is an annoying \"Illegal constructor\" appearing and I cannot figure out why.\r\n\r\nI am trying to set up the React `VideoCapture` element as [mentioned here](https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/v10.4.20/hello-world/react#create-and-edit-the-videocapture-component).\r\n\r\nIt looks like this:\r\n\r\n\u003cdetails>\r\n\r\n\u003csummary>`VideoCapture` element\u003c/summary>\r\n\r\n```tsx\r\nimport React from 'react';\r\n\r\nimport '../dynamsoft.config';\r\n\r\n// --Change starts\r\n// For some reason, import from Dynamsoft does not work. But the library is creating a global\r\n// `Dynamsoft` object that has all the library contents.\r\n\r\n// @ts-ignore\r\nimport \"dynamsoft-camera-enhancer\";\r\n// @ts-ignore\r\nimport \"dynamsoft-capture-vision-router\";\r\n// @ts-ignore\r\nimport \"dynamsoft-utility\";\r\n\r\nconst Dynamsoft = (window as any).Dynamsoft;\r\nconst CameraEnhancer = Dynamsoft.DCE.CameraEnhancer;\r\nconst CameraView = Dynamsoft.DCE.CameraView;\r\nconst CaptureVisionRouter = Dynamsoft.CVR.CaptureVisionRouter;\r\nconst MultiFrameResultCrossFilter = Dynamsoft.Utility.MultiFrameResultCrossFilter;\r\n\r\n// -- Change end\r\n\r\nconst componentDestroyedErrorMsg = \"VideoCapture Component Destroyed\";\r\n\r\nclass VideoCapture extends React.Component\u003c{ onSubmit: Function }, {}> {\r\n  cameraViewContainer: React.RefObject\u003cHTMLDivElement> = React.createRef();\r\n\r\n  resolveInit?: () => void;\r\n  pInit: Promise\u003cvoid> = new Promise((r) => (this.resolveInit = r));\r\n  isDestroyed = false;\r\n\r\n  cvRouter?: typeof Dynamsoft.CVR;\r\n  cameraEnhancer?: typeof Dynamsoft.CE;\r\n\r\n  async componentDidMount() {\r\n    try {\r\n      // Create a `CameraEnhancer` instance for camera control and a `CameraView` instance for UI control.\r\n      const cameraView = await CameraView.createInstance();\r\n      if (this.isDestroyed) {\r\n        throw Error(componentDestroyedErrorMsg);\r\n      } // Check if component is destroyed after every async\r\n\r\n      this.cameraEnhancer = await CameraEnhancer.createInstance(cameraView);\r\n      if (this.isDestroyed) {\r\n        throw Error(componentDestroyedErrorMsg);\r\n      }\r\n\r\n      // Get default UI and append it to DOM.\r\n      this.cameraViewContainer.current!.append(cameraView.getUIElement());\r\n\r\n      // Create a `CaptureVisionRouter` instance and set `CameraEnhancer` instance as its image source.\r\n      this.cvRouter = await CaptureVisionRouter.createInstance();\r\n      if (this.isDestroyed) {\r\n        throw Error(componentDestroyedErrorMsg);\r\n      }\r\n      this.cvRouter.setInput(this.cameraEnhancer);\r\n\r\n      // Define a callback for results.\r\n      this.cvRouter.addResultReceiver({\r\n        onDecodedBarcodesReceived: (result: any) => {\r\n          if (!result.barcodeResultItems.length) return;\r\n\r\n          for (let item of result.barcodeResultItems) {\r\n            this.props.onSubmit(item.text);\r\n          }\r\n        },\r\n      });\r\n\r\n      // Filter out unchecked and duplicate results.\r\n      const filter = new MultiFrameResultCrossFilter();\r\n      // Filter out unchecked barcodes.\r\n      filter.enableResultCrossVerification(\"barcode\", true);\r\n      // Filter out duplicate barcodes within 3 seconds.\r\n      filter.enableResultDeduplication(\"barcode\", true);\r\n      await this.cvRouter.addResultFilter(filter);\r\n      if (this.isDestroyed) {\r\n        throw Error(componentDestroyedErrorMsg);\r\n      }\r\n\r\n      // Open camera and start scanning single barcode.\r\n      await this.cameraEnhancer.open();\r\n      if (this.isDestroyed) {\r\n        throw Error(componentDestroyedErrorMsg);\r\n      }\r\n      await this.cvRouter.startCapturing(\"ReadSingleBarcode\");\r\n      if (this.isDestroyed) {\r\n        throw Error(componentDestroyedErrorMsg);\r\n      }\r\n    } catch (ex: any) {\r\n      if ((ex as Error)?.message === componentDestroyedErrorMsg) {\r\n        console.log(componentDestroyedErrorMsg);\r\n      } else {\r\n        let errMsg = ex.message || ex;\r\n        console.error(errMsg);\r\n        console.log(\"ERROR HERE\");\r\n        console.log(ex);\r\n        alert(errMsg);\r\n      }\r\n    }\r\n\r\n    // Resolve pInit promise once initialization is complete.\r\n    this.resolveInit!();\r\n  }\r\n\r\n  async componentWillUnmount() {\r\n    this.isDestroyed = true;\r\n    try {\r\n      // Wait for the pInit to complete before disposing resources.\r\n      await this.pInit;\r\n      this.cvRouter?.dispose();\r\n      this.cameraEnhancer?.dispose();\r\n    } catch (_) {}\r\n  }\r\n\r\n  shouldComponentUpdate() {\r\n    // Never update UI after mount, sdk use native way to bind event, update will remove it.\r\n    return false;\r\n  }\r\n\r\n  render() {\r\n    return (\r\n      \u003cdiv ref={this.cameraViewContainer} style={{  width: \"100%\", height: \"70vh\" }}>\u003c/div>\r\n    );\r\n  }\r\n}\r\n\r\nexport default VideoCapture;\r\n```\r\n\r\n\u003c/details>\r\n\r\nThe `VideoCapture` component is embedded is another `QRCodeReader` element.\r\n\r\n\u003cdetails>\r\n\r\n\u003csummary>`QRCodeReader` element\u003c/summary>\r\n\r\n```jsx\r\nimport { useState } from 'react';\r\nimport VideoCapture from \"./VideoCapture\";\r\n\r\nconst QRCodeReader = (props) => {\r\n    const [errors, setErrors] = useState(null);\r\n\r\n    const onSubmit = async (param) => {\r\n        try {\r\n            const isUpdated = await props.onSubmit(param);\r\n            if (isUpdated) {\r\n                setErrors(null);\r\n            }\r\n        } catch(error){\r\n            setErrors(error);\r\n        }\r\n    }\r\n\r\n    return (\r\n        \u003cdiv>\r\n            \u003cVideoCapture onSubmit={onSubmit} />\r\n            {errors}\r\n        \u003c/div>\r\n    );\r\n}\r\n\r\nexport default QRCodeReader;\r\n```\r\n\r\n\u003c/details>\r\n\r\nUntil here, everything works well. Using the `QRCodeReader` element, it can scan QRCode and extract the item elements. Nice.\r\n\r\nThe issue happens after that, when I try to embed the `QRCodeReader` element into a `QRModal` Element.\r\nElements looks like this `VideoCapture \u003c- QRCodeReader \u003c- QRModal`.\r\n\r\nWe want to use them in a process that is the following: \r\n- first scan: uses the `QRCodeReader` (full page reader).\r\n- updates the page to match info in the QRCode, loads a list of items from db on the page, each item has a scan modal button to trigger the `QRModal`, to access the detail of each item, we must scan again using the modal.\r\n- second scan: uses the `QRModal` (modal reader) -> `fails consistently with the same error`.\r\n\r\n\u003cdetails>\r\n\r\n\u003csummary>`QRModal` element\u003c/summary>\r\n\r\n```jsx\r\nimport React, {useEffect, useState} from 'react';\r\nimport PropTypes from 'prop-types';\r\nimport Modal from 'Modal';\r\nimport QRCodeReader from './QRCodeReader';\r\n\r\n/**\r\n * Widget to access a profile using a QR code\r\n *\r\n * @param {object} props - React props\r\n *\r\n * @return {ReactDOM}\r\n */\r\nconst QRModal = (props) => {\r\n  const [code, setCode] = useState(null);\r\n\r\n  useEffect(() => {\r\n  }, []);\r\n\r\n  return (\r\n    \u003cModal\r\n      onClose={() => {\r\n        props.onClose();\r\n      }}\r\n      show={true}\r\n      title={props.modalTitle}\r\n    >\r\n      \u003cQRCodeReader onSubmit={(c) => {\r\n        if (c === code) return;\r\n        setCode(c);\r\n        props.onScan(c);\r\n      }} />\r\n    \u003c/Modal>\r\n  );\r\n}\r\n\r\nQRModal.defaultProps = {\r\n  modalTitle: 'Scan QR Code',\r\n};\r\n\r\nQRModal.propTypes = {\r\n  modalTitle: PropTypes.string,\r\n};\r\n\r\nexport default QRModal;\r\n```\r\n\r\n\u003c/details>\r\n\r\n\r\nThis is throwing a `Type Error: Illegal constructor.` apparently coming from `CameraView.createInstance()`.\r\n\r\nI also tried to directly shortcut QRModal to directly call another VideoCapture class (`VideoCapture2` is a copy of `VideoCapture`). Same result.\r\n\r\n![image](https://github.com/user-attachments/assets/24aad2b9-50d3-4e48-b1d8-f62bd83345f3)\r\n\r\n","author":{"url":"https://github.com/regisoc","@type":"Person","name":"regisoc"},"datePublished":"2024-11-15T15:21:15Z","url":"https://github.com/Dynamsoft/barcode-reader-javascript/issues/154"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:3517785c-17d2-f4f6-0d1b-03bff4f61dfe
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA42A:1F7384:1322FFB:194C6AE:6B011E5A
html-safe-nonce8c6b0e3bb927e6d917c5e2c52c39a867e700dd90a17a91bf619dadd57e468210
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNDJBOjFGNzM4NDoxMzIyRkZCOjE5NEM2QUU6NkIwMTFFNUEiLCJ2aXNpdG9yX2lkIjoiMTkxOTE3MjQ4MTYyNjM1MzU0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac6082524904277f8901f8a9f8d87b7af51ea240ea8a338f720b843df42f745733
hovercard-subject-tagissue:2662288283
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/Dynamsoft/barcode-reader-javascript/154/issue_layout
twitter:imagehttps://opengraph.githubassets.com/c035d528b791dcb6b7d9999f686d7f4522d0d686b4dbd2d75e97cd9e597fce57/Dynamsoft/barcode-reader-javascript/issues/154
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/c035d528b791dcb6b7d9999f686d7f4522d0d686b4dbd2d75e97cd9e597fce57/Dynamsoft/barcode-reader-javascript/issues/154
og:image:altHello, Short version: maybe I am just blind after some hours spent on that. There is an annoying "Illegal constructor" appearing and I cannot figure out why. I am trying to set up the React VideoCa...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameregisoc
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
go-importgithub.com/Dynamsoft/barcode-reader-javascript git https://github.com/Dynamsoft/barcode-reader-javascript.git
octolytics-dimension-user_id5820187
octolytics-dimension-user_loginDynamsoft
octolytics-dimension-repository_id145683056
octolytics-dimension-repository_nwoDynamsoft/barcode-reader-javascript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id145683056
octolytics-dimension-repository_network_root_nwoDynamsoft/barcode-reader-javascript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/Dynamsoft/barcode-reader-javascript/issues/154#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FDynamsoft%2Fbarcode-reader-javascript%2Fissues%2F154
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FDynamsoft%2Fbarcode-reader-javascript%2Fissues%2F154
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=Dynamsoft%2Fbarcode-reader-javascript
Reloadhttps://github.com/Dynamsoft/barcode-reader-javascript/issues/154
Reloadhttps://github.com/Dynamsoft/barcode-reader-javascript/issues/154
Reloadhttps://github.com/Dynamsoft/barcode-reader-javascript/issues/154
Dynamsofthttps://github.com/Dynamsoft
barcode-reader-javascripthttps://github.com/Dynamsoft/barcode-reader-javascript
Codehttps://github.com/Dynamsoft/barcode-reader-javascript
Issues8 (8)https://github.com/Dynamsoft/barcode-reader-javascript/issues
Pull requests1 (1)https://github.com/Dynamsoft/barcode-reader-javascript/pulls
Actionshttps://github.com/Dynamsoft/barcode-reader-javascript/actions
Projectshttps://github.com/Dynamsoft/barcode-reader-javascript/projects
Security and qualityhttps://github.com/Dynamsoft/barcode-reader-javascript/security
Insightshttps://github.com/Dynamsoft/barcode-reader-javascript/insights
https://github.com/Dynamsoft/barcode-reader-javascript
New issuehttps://github.com/login?return_to=https://github.com/Dynamsoft/barcode-reader-javascript/issues/154
New issuehttps://github.com/login?return_to=https://github.com/Dynamsoft/barcode-reader-javascript/issues/154
Illegal constructorhttps://github.com/Dynamsoft/barcode-reader-javascript/issues/154#top
https://github.com/regisoc
regisochttps://github.com/regisoc
on Nov 15, 2024https://github.com/Dynamsoft/barcode-reader-javascript/issues/154#issue-2662288283
mentioned herehttps://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/v10.4.20/hello-world/react#create-and-edit-the-videocapture-component
https://private-user-images.githubusercontent.com/25327259/386657729-24aad2b9-50d3-4e48-b1d8-f62bd83345f3.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3OTUyMzU3MTksIm5iZiI6MTc5NTIzNTQxOSwicGF0aCI6Ii8yNTMyNzI1OS8zODY2NTc3MjktMjRhYWQyYjktNTBkMy00ZTQ4LWIxZDgtZjYyYmQ4MzM0NWYzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjExMjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYxMTIxVDA0MzAxOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWJkYzU2MDI0NjMzODM1Njg0MTJlYzgxN2E1YmNjNTExZjc4Nzc2NmExNjVlM2ViOTRlOGMxOWIxY2MyNzNhNDQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JnJlc3BvbnNlLWNvbnRlbnQtdHlwZT1pbWFnZSUyRnBuZyJ9.4asOjOb1IYWw97aFUria7SH6N34h4KDHCrNfB7AuqMo
https://github.com/Keillion
Keillionhttps://github.com/Keillion
on Nov 18, 2024https://github.com/Dynamsoft/barcode-reader-javascript/issues/154#issuecomment-2482452628
https://github.com/Keillion
Keillionhttps://github.com/Keillion
on Nov 18, 2024https://github.com/Dynamsoft/barcode-reader-javascript/issues/154#issuecomment-2482458406
https://github.com/regisoc
regisochttps://github.com/regisoc
on Nov 18, 2024https://github.com/Dynamsoft/barcode-reader-javascript/issues/154#issuecomment-2483150425
@Keillionhttps://github.com/Keillion
https://github.com/regisoc
regisochttps://github.com/regisoc
on Nov 20, 2024https://github.com/Dynamsoft/barcode-reader-javascript/issues/154#issuecomment-2488882771
@Keillionhttps://github.com/Keillion
https://github.com/Keillion
Keillionhttps://github.com/Keillion
on Nov 21, 2024https://github.com/Dynamsoft/barcode-reader-javascript/issues/154#issuecomment-2490191618
https://github.com/regisoc
regisochttps://github.com/regisoc
on Nov 21, 2024https://github.com/Dynamsoft/barcode-reader-javascript/issues/154#issuecomment-2491433735
regisochttps://github.com/regisoc
completedhttps://github.com/Dynamsoft/barcode-reader-javascript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Nov 21, 2024https://github.com/Dynamsoft/barcode-reader-javascript/issues/154#event-15383403495
https://github.com/Keillion
Keillionhttps://github.com/Keillion
on Nov 22, 2024https://github.com/Dynamsoft/barcode-reader-javascript/issues/154#issuecomment-2492886653
Keillionhttps://github.com/Keillion
on Nov 22, 2024https://github.com/Dynamsoft/barcode-reader-javascript/issues/154#event-15392211847
Sign up for freehttps://github.com/signup?return_to=https://github.com/Dynamsoft/barcode-reader-javascript/issues/154
Sign in to commenthttps://github.com/login?return_to=https://github.com/Dynamsoft/barcode-reader-javascript/issues/154
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.