question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compatibility - globalThis preventing use in older browsers

See original GitHub issue

Describe 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:open
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
mebjascommented, Jun 16, 2021

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.

0reactions
ROBERT-MCDOWELLcommented, Jun 16, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to polyfill `globalThis` into older browsers? - Stack Overflow
All of the issues seem to be relatively new JavaScript being used by sites that isn't compatible with older or non-Chromium/Firefox browsers, ...
Read more >
"globalThis" | Can I use... Support tables for HTML5, CSS3, etc
"Can I use" provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.
Read more >
globalThis - JavaScript - MDN Web Docs
Note: The globalThis property is configurable and writable so that code authors can hide it when executing untrusted code and prevent exposing ...
Read more >
How to resolve JavaScript Cross Browser Compatibility Issues
Using modern JavaScript features on Older Browsers. Primarily errors in JavaScript browser compatibility pop up when website developers try to ...
Read more >
Stop using `this` instead use `globalThis` for global variables
You can use it right now it is supported by all major Browsers besides IE11. But should we really care about a 7-year-old...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found