Compatibility - globalThis preventing use in older browsers
See original GitHub issueDescribe the bug
There is a globalThis
call in html5-qrcode.min.js. Using globalThis
dramatically raises the minimum required browser versions. Doing globalThis || global || self || window
is not a workaround, because accessing the globalThis
raises an exception. The proper workaround should be:
var getGlobal = function () { if (typeof self !== ‘undefined’) { return self; } if (typeof window !== ‘undefined’) { return window; } if (typeof global !== ‘undefined’) { return global; } throw new Error(‘unable to locate global object’); };
var globals = getGlobal();
or even only editing the code to self || window || global
.
More info here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
Describe the browser (tested on):
- OS: Windows
- Browser: chrome
- Version: 49
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top GitHub Comments
it’s coming from https://github.com/mebjas/html5-qrcode/blob/master/third_party/zxing-js.umd.js (fork of Zxing library in this project).
I’ll try to fix it as you mentioned.
The best solution I found is to put on top of the code const globalThis = this[“globalThis”] || this[‘global’] || this[‘self’] || this[‘window’] || null; browser not recognizing globalThis now works.