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.

Extending some native object doesn't work in IE11

See original GitHub issue

Bug Report

Current Behavior

IE11 throws a runtime error when transpiling class extension for native objects like: Foo class extends DocumentFragment {}

The problem is in this helper:

function _isNativeFunction(fn) {
  return Function.toString.call(fn).indexOf("[native code]") !== -1;
}

Here is the runtime error:

Function.prototype.toString: 'this' is not a Function object

The issue appears to be because superClass needs to be a function but typeof HTMLElement is object (in IE11) Note that typeof HTMLElement is function in other browsers.

Input Code

  • REPL or Repo link if applicable:

https://babeljs.io/repl/build/9254/#?babili=false&browsers=&build=&builtIns=false&spec=false&loose=false&code_lz=MYGwhgzhAEAa0FMAeAXBA7AJjAIge2AFcBbDFAMQCcwBzU9FaAbwCgBfFl4PdCPEBADoQeGgApYASgDcQA&debug=true&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=false&presets=env&prettier=true&targets=&version=7.1.2%2Bpr.8878&envVersion=7.1.0%2Bpr.8878

class X extends DocumentFragment {}

Expected behavior/code It should work? 😃

Possible Solution I haven’t though too much about it, but maybe another check for isNative will be sufficient

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:13
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
ghostcommented, Jun 25, 2019

To save you sometime, add the following after your custom element polyfills:

<script>if (typeof HTMLElement === 'object') document.write('<script src="https://unpkg.com/custom-elements-es5-adapter@@1.0.0/custom-elements-es5-adapter.js" crossorigin="anonymous"><' + '/script>')</script>

In my case, it would look like this:

<script>if (this.customElements) try { customElements.define('built-in', document.createElement('p').constructor, { 'extends': 'p' }) } catch (a) { document.write('<script src="https://unpkg.com/@@ungap/custom-elements-builtin@0.2.7/min.js" crossorigin="anonymous" ><' + '/script>') } else document.write('<script src="https://unpkg.com/document-register-element@1.13.2/build/document-register-element.js" crossorigin="anonymous" ><' + '/script>');</script>

<!-- On IE11, typeof HTMLElement === 'object',
    this breaks babel 7/TS compilation of built in extension
    Adding an adapter to add an intermediate constructor wrapping native HTMLElement to fix this issue
-->
<script>if (typeof HTMLElement === 'object') document.write('<script src="https://unpkg.com/custom-elements-es5-adapter@@1.0.0/custom-elements-es5-adapter.js" crossorigin="anonymous"><' + '/script>')</script>
3reactions
FNDcommented, Feb 6, 2019

FWIW, I just ran into this issue and turns out I’d simply forgotten to include the Custom Elements polyfill (document-register-element in my case) required for IE 11. Not sure whether that invalidates this issue, but perhaps mentioning it here saves others some trouble.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error in IE 11 browser - EXCEPTION: Object doesn't support ...
11 it shows error as error comes in IE 11 DEVELOPER TOOLS. The error shows up in developer tools of the IE 11....
Read more >
Browser Compatibility of Object.entries on Internet Explorer 11
Object.entries is Not Supported on Internet Explorer 11. Checkout overall cross browser compatibility of Object.entries on Internet Explorer ...
Read more >
Fix web compatibility issues using document modes and the ...
Go to a site having compatibility problems, press F12 to open the F12 Developer Tools, and go to the Emulation tool. Emulation tool...
Read more >
Merging objects with vanilla JavaScript | Go Make Things
Vanilla JavaScript doesn't offer any native method to merge ... The Basic Approach To make this work, we want to create an empty...
Read more >
Using IndexedDB - Web APIs - MDN Web Docs
The open request doesn't open the database or start the transaction ... You can also create indices on any object store, provided the...
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