GithubHelp home page GithubHelp logo

gruhn / vue-qrcode-reader Goto Github PK

View Code? Open in Web Editor NEW
2.0K 34.0 325.0 10.57 MB

A set of Vue.js components for detecting and decoding QR codes.

Home Page: https://gruhn.github.io/vue-qrcode-reader

License: MIT License

JavaScript 0.89% Vue 44.47% Shell 0.31% Nix 0.53% TypeScript 53.80%
qrcode-reader vuejs qrcode-scanner vue webrtc vue-component vue-components vue-plugin qr-code qr-codes

vue-qrcode-reader's Introduction

Logo

for Vue 3 npm monthly downloads
is maintained? yes licence: MIT badges = awesome
uses semantic release code style: prettier
size minified + gzipped npm current version
Mentioned in Awesome Vue

live demos | api reference

A set of Vue.js components for detecting QR codes and various other barcode formats right in the browser:

  • ๐ŸŽฅ QrcodeStream continuously scans frames from a camera stream.
  • ๐Ÿšฎ QrcodeDropZone is an empty region where you can drag-and-drop images to be decoded.
  • ๐Ÿ“‚ QrcodeCapture is a classic file upload field, instantly scanning all files you select.

All components are responsive. Beyond that, close to zero styling. Make them fit your layout. Usage is simple and straight forward:

<qrcode-stream @detect="onDetect"></qrcode-stream>
methods: {
  onDetect (detectedCodes) {
    // ...
  }
}

Preview

preview screencast 1 preview screencast 2

Installation ๐Ÿ“ฆ

With NPM

Run

npm install vue-qrcode-reader

You can import the components independantly

import { QrcodeStream, QrcodeDropZone, QrcodeCapture } from 'vue-qrcode-reader'

const MyComponent = {
  //
  components: {
    QrcodeStream,
    QrcodeDropZone,
    QrcodeCapture
  }

  // ...
}

or register all of them globally right away

import Vue from 'vue'
import VueQrcodeReader from 'vue-qrcode-reader'

Vue.use(VueQrcodeReader)

Without NPM

Include the following JS file:

https://unpkg.com/vue-qrcode-reader/dist/vue-qrcode-reader.umd.js

Make sure to include it after Vue:

<script src="./vue.js"></script>
<script src="./vue-qrcode-reader.umd.js"></script>

All components are automatically registered globally. Use kebab-case to reference them in your templates:

<qrcode-stream></qrcode-stream>
<qrcode-drop-zone></qrcode-drop-zone>
<qrcode-capture></qrcode-capture>

Troubleshooting โšก

I don't see the camera when using QrcodeStream.

  • Check if it works on the demo page. Especially the Handle Errors demo, since it renders error messages.
    • The demo works but it doesn't work in my project: Listen for the error event to investigate errors.
    • The demo doesn't work: Carefully review the Browser Support section above. Maybe your device is just not supported.

I'm running a dev server on localhost. How to test on my mobile device without HTTPS?

  • If your setup is Desktop Chrome + Android Chrome, use Remote Debugging which allows your Android device to access your local server as localhost.
  • Otherwise use a reverse proxy like ngrok or serveo to temporarily make your local server publicly available with HTTPS.
  • There are also loads of serverless/static hosting services that have HTTPS enabled by default and where you can deploy your web app for free (e.g. GitHub Pages, GitLab Pages, Google Firebase, Netlify, Heroku, ZEIT Now, ...)

Some of my QR codes are not being detected.

  • Make sure, there is some white border around the QR code.
  • Test your QR codes in the upstream packages: barcode-detector -> zxing-wasm -> zxing-cpp, and file detection issues in the highest-level repository where the problem first occurs.

1D barcodes are not being detected.

The default value for the formats prop is "['qr_code']", which reflects the setting before the formats prop was available. You'll need to add other barcode formats to this prop to detect those types of barcodes. Check out this demo.

How to make it work with Vue 2?

Support is dropped but you can downgrade to vue-qrcode-reader v3.* or lower.

I get a "Failed to fetch" error at runtime for some Wasm file.

That Wasm file implements the QR code detector. Unfortunately, it's not very convenient to bundle this file with the package. So by default we fetch it at runtime from a CDN. That's an issue for offline applications or applications that run in a network with strict CSP policy. For a workaround see: #354

torch is not supported on my device, although it has a flashlight.

Support for torch is inconsistent across devices, cameras and browsers and operating systems. On some devices the rear camera supports torch but the front camera doesn't, even if the front camera actually has a flashlight.

Furthermore, torch is not supported on iOS at all (last checked iOS 17.1).

Visit this page with your device. The list of links represents all cameras installed on the device. If you click, the camera should be loaded. Below the camera view the JSON object of "capabilities" is printed. If it doesn't contain the key/value pair "torch": true then flashlight is not supported for that camera.

This JSON object provided as payload of the camera-on event.

vue-qrcode-reader's People

Contributors

777vasya77 avatar adriangoransson avatar afontcu avatar b4r7 avatar cinob avatar danbaechtold avatar dargmuesli avatar dbakan avatar dependabot[bot] avatar gewra avatar glumb avatar gruhn avatar hyrumcoop avatar iqre8 avatar jkathmann avatar jovan-aw avatar limsongyu avatar pamtaro avatar paulwer avatar robwalker avatar samydoesit avatar sec-ant avatar stepanex avatar uwolfer avatar v-dyomin avatar vpulim avatar yannic-bruegger-voss avatar yaroslawww avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-qrcode-reader's Issues

Is there any simple example of how to use this?

Im trying to understand how to use this on a simple white html page, but demo page does not have a simple read code (some obfuscade js and not divs)... browser instructions says "<script src="vue.js"></script>" and there is no vue.js file, if you go to sample source files they are a .vue files, there is no a index.html file or something to start to work with, i think that a simple "example" folder with a index.html file and link to js would be helpful for newbies,

h is not a function type error on browser version

Hi,

I try to run the vue code directly from browser.

After all, execution exception happened.

here is the segment of the code

keepDecoding: function() {
                    var e = this;
                    if (this.shouldDecode) {
                        var t = this.captureFrame();
                        window.requestAnimationFrame(function() {
                            var r = t.data
                              , n = t.width
                              , i = t.height
                              , o = h()(r, n, i);  // this is error
                            null !== o && (e.decodeResult = o.data),
                            window.setTimeout(e.keepDecoding, 400)
                        })
                    }
                },

Drag and Drop Image to decode

In some situations its not possible to access the camera device (e.g. no camera present/not supportet api)
In such cases it would be nice to be able to drag and drop or file choose an image to feed to the decoder which is already there.
The Panel could be a AspecRatio container derived from the video constraints or extra parameters to the component. AR settings should superseed height/width these days.

Best regards and thanks for the great work so far! Using your component in cooking-cloud.com App. so far no bugs/error reports from testing people

TypeError: Cannot read property 'style' of undefined

I have this in my Vue file:

<qrcode-reader @init="onInit" @decode="onDecode"></qrcode-reader>

I get the following error in my dev tools console:

TypeError: Cannot read property 'style' of undefined
    at VueComponent.unlockCameraLayerSize (vue-qrcode-reader.common.js?673c:1)
    at VueComponent.startPlayback (vue-qrcode-reader.common.js?673c:1)
    at VueComponent.eval (vue-qrcode-reader.common.js?673c:1)
    at r (vue-qrcode-reader.common.js?673c:1)
    at Generator.eval [as _invoke] (vue-qrcode-reader.common.js?673c:1)
    at Generator.t.(:8080/anonymous function) [as next] (webpack-internal:///./node_modules/vue-qrcode-reader/dist/vue-qrcode-reader.common.js:1:39060)
    at r (vue-qrcode-reader.common.js?673c:1)
    at eval (vue-qrcode-reader.common.js?673c:1)

Making scan area squared

Hi, great lib, works fine when not setting :video-constraints, however when
I've tried by first setting aspectRatio: 1 and later
<qrcode-reader @decode="onDecode" @init="onInit" :video-constraints="{ width: { min: 360, ideal: 360, max: 360 }, height: { min: 360, ideal: 360, max: 360 } }" />

I'm just getting a blinking scan area (where I can see it's squared) and
image

This was in Chrome 66 in Mac OS.

Any thoughts?

pngquant` binary doesn't seem to work correctly

[user@server xxxxxxxxxx]$yarn add vue-qrcode-reader
yarn add v1.7.0
info No lockfile found.
[1/4] Resolving packages...
warning laravel-mix > img-loader > imagemin-optipng > optipng-bin > bin-wrapper > download > gulp-decompress > [email protected]: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
[2/4] Fetching packages...
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
[6/6] โ  node-sass
[-/6] โ  waiting...
[3/6] โ  mozjpeg
[-/6] โ  waiting...
error /home/xxxxx/xxxxxxx/node_modules/pngquant-bin: Command failed.
Exit code: 1
Command: node lib/install.js
Arguments:
Directory: /home/vauroleseg/dashboard/node_modules/pngquant-bin
Output:
โš  The /home/xxxxx/xxxxxxxxx/node_modules/pngquant-bin/vendor/pngquant binary doesn't seem to work correctly
โš  pngquant pre-build test failed
โ„น compiling from source
โœ” pngquant pre-build test passed successfully

catch uncaught (in promise)

The async function to handle init event cannot catch promise rejection error inside try - catch block. Seems like the reject method was not implemented in promise object passed. I used the sample in its doc as:

 methods: {
  async onInit (promise) {
    // show loading indicator
    try {
      await promise
      // successfully initialized
    } catch (error) {
      if (error.name === 'NotAllowedError') {
        // user denied camera access permisson
      } else if (error.name === 'NotFoundError') {
        // no suitable camera device installed
      } else if (error.name === 'NotSupportedError') {
        // page is not served over HTTPS (or localhost)
      } else if (error.name === 'NotReadableError') {
        // maybe camera is already in use
      } else if (error.name === 'OverconstrainedError') {
        // passed constraints don't match any camera. Did you requested the front camera although there is none?
      } else {
        // browser is probably lacking features (WebRTC, Canvas)
      }
    } finally {
      // hide loading indicator
    }
  }
}

I get the console error in chrome:

Uncaught (in promise) vue-qrcode-reader.common.js?1730:1

IE11 / EDGE not supported

Nothing to say related to explorer but yes regarding MS Edge. Seems like it does not like the promises, so I get this: 'Unhandled promise rejection SourceUnavailableError'. Do you know if is it possible to enable this?
BTW: Really awsome plugin!

Does anybody use the locate event?

Does anybody use locate for anything other than painting the QR code position over the camera stream like in the Track location demo?

I think it might be a good idea to provide this out of the box and remove locate. Maybe by introducing a prop called track. You could pass true/false to enable this tracking or pass a repaint function to customize painting. This function would be called to produce each frame. This could look somewhat like this:

<qrcode-reader :track="repaint"></qrcode-reader>
methods: {
  repaint (canvas2dContext, locationArray) {
    // paint the location to the canvas
  }
}

Reactive property mutation (live stuff in dataor computed) in response to locate events can become really memory intensive. I believe this is because Vue handles reactive property updates asynchronously. locate can be triggered several times a second. This fills up the event loop or something. I'm not really sure there but replacing locate with track should avoid this problem.

If you like/don't like this idea, have additional suggestions or have a different use case for locate please come forward ๐Ÿ˜Š

Access camera picture

Hello

Is it somehow possible to access raw image from the camera using vue-qrcode-reader? I saw that jsQR allows that so my question is is the functionality somehow exposed by this library?

What I want to achieve is to have a snapshot of the whole frame at the moment when a code was decoded but not sure how to get there

cropped scan area

Hi! this is nice code.
Well, how a can i to transfer the scan area to the decoder?
eg:
if the aspect ratio of the video stream is 1280x720, then I want to scan only 600x600 in the middle of the video

Migrate to vue-cli 3

vue-qrcode-reader was scaffolded with vue-cli 2 and the vue-share-components template. Since vue-cli 3 stable release is out, which supports library builds out of the box and has some other handy features, it would be cool to migrate.

Page is not loading qrcode-reader

I installed thispackage and I want to use it in my qrscan.blade.php and i put everything like you said in app.js and made in components file vue-qrcode-reader and put code from TheFirstResultDemo.vue in it and its just not working. Can someone help me get this package to work?

this is my qrscan.blade.php

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Vue</title>
		<link href="{{ mix('css/app.css') }}" rel="stylesheet" type="text/css">
    </head>
    <body>
        <div id="app"></div>
                <qrcode-reader @decode="onDecode" :paused="paused"></qrcode-reader>
		<script src="{{ mix('js/app.js') }}"></script>
    </body>
</html> 

Improve performance with WebAssembly

Scanning a frame for QR codes is a rather expensive operation. The library responsible for this job (jsQR) also makes up a major part of the bundle size. Maybe performance could be increased by using a WebAssembly module instead. This component depends on modern browser features anyway so browser support shouldn't suffer too bad?

[Feature] Set default camera.

I use this library on the device with 2 cameras (Front and Back). Could add a feature to set default camera. Or how to set default camera in code. Thank

this.$listeners is undefined. Quasar framework integration.

Hi, Can this be implemented using quasar-framework?
I have an issue using this package in my current project which is built using quasar-framework v.14.1.
My use case is to embed the qr-code-reader in a modal. The webcam can be successfully detected and can be displayed inside the modal but there is an error which is preventing me to scan a QRCode.
This is the error I get. It states that this.$listeners is undefined
image

Unable to read QR code

Hi,
I am trying demo page here on my phone.
QR code used is one that is immediately scanned by native Android applications (I have tried 4-5 different Android applications, all worked without any problem).
Here, tried to test it on demo page and I am unable to get QR scanned.
Am I missing something obvious or maybe there is problem with phone used for test (Huawei CAN-L11, Android 7.0 ) ?
On some other HTML demos, on Internet, QR codes are read but was very slow, ex: 10-20 seconds), or also didn't work.
Is this something known?
Which QR code you use for tests?

Also I have tried using laptop and also QR kod was not recognized. As in the case with the phone, camera is activated, grant given to access it, QR is visible by camera, as shown on the page. Still, QR code is not recognized.

Thank you,
Igor

System requirements?

I'm tried to use this component but it doesn't work on my iPhone 5 v.10.3.2

What is system requirements for this component?

There is error from your site:
jxzoqmblq6y

This error in Safari and Chrome(newest)

Captured frames transformed on mobile

On my Android 5 phone with Chrome 61 and WebView 61 installed, frames captured (by painting to a canvas) from the camera stream are sometimes rotated or only contain a fragment of the actual frame. Since this captured frame is scanned for QR codes, the detection process is compromised. Detected QR code module positions for example appear in the wrong place. Also, QR codes are sometimes not detected at all although clearly visible in the stream.

The problem does not occur on my desktop Chrome (same version).

Rescanning issue

I have some an app that requires certain QR codes to be scanned more than once in a row, if there were a way to set a reset time of sorts so that a QR code could be rescanned after 5 seconds (or any time for that matter).

Feature Request - pauseHard Camera

Hi,
first of all: Works like a Charm and a very nice piece of Code!

Im using this in Browsers on mobile devices and as long as the component is mounted Chrome displays a Notification that there is an 'Access to Video Camera from domain'. Even if the Browser is in background or switched to an different Tab.

Would it be possible for your to expose a pauseHard() function which disconnects the Camera but keeps the last image in the canvas?

Calling stopCamera() works but kills the canvas or blacks it out

This works with barcode??

Hi, I like this, but i tried to scan a bar code, and is not happen nothing,
so my question is,
This works with barcode??

Bebel problem

I don't know what the magical polifyll do you use, but i got error out of the box.

Uncaught ReferenceError: regeneratorRuntime is not defined

I took code from demo and seems init method does not work. I don't see any text in row. So i see my face about 30 minutes and no reaction on any qr code.

I set babel language to fix error
<script lang="babel">

But it seems like I'm doing something wrong.

Component not working on mobile patforms

Hi there,

Great component by the way. Works fine in the web browser(Google Chrome).

However I have hard time with it when it comes to loading it on mobile. Tryed with Safari and Google Chrome on iPhone 6 and it fails. It's not being loaded at all, and when I try pc's browser responsive option it loads fine there.

I hope you will give me some hints on how to make this work, since I'm stuck.

how do i reinit component?

i use this component inside vuetify v-dialog, in the first open, scanner is working perfectly, but for next operation mostly method onDecode never called (camera played no problem), i think the component should be init when dialog open (in my case), so there any way to do that (reinit)?

Use jsqr 1.0.6

Hello,

Can package "vue-qrcode-reader" use jsqr 1.0.6 ?
There're some useful changes\fixes since 1.0.4 especially following issue:
cozmo/jsQR#68

Undefined VERSION on every update

I'm using the plugin successfully in every aspect except that it seems to look for a VERSION variable that is undefined everytime I update npm. I've located and modified (against explicit orders) the following code on src/index.js

// Plugin
const plugin = {
  /* eslint-disable no-undef */
  version: VERSION,
  install,
}

Still, on every update I have to change the VERSION for an integer (1). Any suggestions?

Can't trigger access to mobile device camera (Adonuxt)

Hi,

Running Adonuxt - accessing the page on mobile device doesn't trigger any qrcode activity (i.e. doesn't ask me to access the camera at all). Your demo works perfectly, though! Do you know what I need to do to get it to run on mobile (iOS/Safari)?

Awesome tool. by the way, worked perfectly on my laptop.

Example code issue ?

Hello ! thanks for your library !
however I have an issue.... I used your demo code but it doesn't work on Chrome on MacOS, Firefox for mac or Chrome on android. The decode and locate events are not triggered. I have no log to provide (no issue in console).
I tried using https and localhost. thanks for your help !
In attachment : Vue.js debugger in Chrome. locate and decode events seem triggered very late (few minutes after..)
capture d ecran 2018-04-19 a 11 35 13

why box out of qr code

hi,

i wanna ask more
i already implement this component, but red box, far away from qr code in camera
how to solved it?

Lodash Issue

Hi,

I just started using this plugin, so my apologies if I rushed ahead. I am importing (downloaded from the dist folder) the css file and JS file (the -browser one) in my index.html. When I open up Chrome and check the dev console, I am getting many errors related to Lodash.

vue.js:580 [Vue warn]: Error in getter for watcher "constraintsNormalized": "TypeError: __WEBPACK_IMPORTED_MODULE_5_lodash_isObject___default(...) is not a function"

found in

---> <QrcodeReader>
       <Root>

Please let me know if you need any more information!

iOS 11 Safari does not init video

Seems like the video can not initialise in latest mobile Safari.
init event says 'NotAllowedError'

I've tried to use solution from this webrtc issue:

mounted() {
    let videoEl = document.getElementsByTagName('video')[0];
    videoEl.setAttribute('autoplay', true);
    videoEl.setAttribute('playsinline', true);
    videoEl.setAttribute('controls', true);
},

But no success.

Empty result

Hello. I hope this package will be useful for me, but...
When DOM is ready i see only slot text. Seems it's even mounted

image

but i don't see anything. No any error, just empty.

Also would be great to have online demo for this.
(and my respect for using BEM ;) )

[Bug] TypeError: Cannot read property 'stop' of null

Hi! Thanks for sharing such a great code, it's useful for me.
But there is a problem still confusing me.

When I ran the demo on a desktop without any camera devices, and chose the different demo option, the following error occurred.

TypeError: Cannot read property 'stop' of null
    at a.beforeDestroy (vue-qrcode-reader.common.js:1)
    at Pt (vue.runtime.esm.js:2813)
    at a.t.$destroy (vue.runtime.esm.js:2598)
    at destroy (vue.runtime.esm.js:4027)
    at _ (vue.runtime.esm.js:5553)
    at a.__patch__ (vue.runtime.esm.js:5865)
    at a.t.$destroy (vue.runtime.esm.js:2621)
    at destroy (vue.runtime.esm.js:4027)
    at _ (vue.runtime.esm.js:5553)
    at b (vue.runtime.esm.js:5569)

After studying the code, I found that the problem might be in the /src/components/QrcodeReader.vue line 175.

beforeDestroy () {
this.camera.stop()
this.destroyed = true
},

Is it possible to check if the this.camera is null or not before stop() it?

Thanks!

force use of rear camera

I'm using Google Chrome on Android 7.0. On some devices like Samsung Galaxy S/A series vue-qrcode-reader uses rear camera and on some devices like Xiaomi Redmi Note 4 it uses front camera. How can I force it to use rear camera?

`QrcodeStream` not supported in iOS Chrome, iOS Firefox, ...

I have implemented vue-qrcode-reader into my Vue application, and it is working great in Mac desktop Chrome, Firefox and Safari, as well as mobile Safari. However in iOS Chrome, it is not working and appears to be returning the NotSupportedError error name...however the documentation states that it is supported. And yes, my site is served over https.

Any thoughts or help would be greatly appreciated

Reset content after scan (on "unPause")

Awesome component, thanks!

However I would like the option to redeem the same code again (in my case after it has been paused), something that isn't possible at the moment because of:

watch: {
    content (newValue) {
      this.$emit('decode', newValue)
    },
   ...
}

Since this.content isn't updated once it's set

A solution might be to add an 'resetOnUnpause'-prop and add 'paused' to 'watch':

props: {
     ...,
    resetOnUnpause : {
      type: Boolean,
      default: false,
    },
  }

watch: {
   paused(newValue) {
      if (this.resetOnUnpause && !newValue)
         this.content = null
   }
}

Is this something you might be willing to add or should I contribute myself?

Thanks again!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.