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.

Support option to set polyfills

See original GitHub issue

Describe the feature you’d like I know you are inclined to not include polyfills directly and prefer to leave it to consumers of this library to define any necessary polyfills. This is fine for consumers who can control which polyfills are set on the page. But this poses a problem for CMPs using your library that have less control over the polyfills a publishers includes on their page.

Currently, the only option seems to be to have our CMP define global polyfills. This is not the preferred approach. Libraries should not set global polyfills affecting code outside of the library.

Option 2 would be for the iabtcf library to include polyfills directly. This would increase the size of the iabtcf library and may not be desired by everyone.

Option 3 (my feature request) is to expose a way for consumers to provide polyfills to the iabtcf library. For example, the consumer code to pass in polyfills might look like

import {Polyfills} from '@iabtcf/core';
import Map from 'es6-map/implement';

Polyfills.Map = Map;

and the iabtcf code would use Polyfills.Map if it exists else default to the globally available Map.

From my testing, the polyfills required for IE 10+ compatibility include

  • Promise
  • Map
  • Set
  • Symbol
  • Array.includes - only used a few times in the core. Perhaps this could be replaced with indexOf to avoid compatibility issues with IE.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:16

github_iconTop GitHub Comments

1reaction
nealrosen04commented, Apr 3, 2020

I have not been able to get @babel/runtime to work. It seemed to work to inject polyfills into my own source code, but didn’t seem to update anything in this library, possibly because this library code is in my node_modules instead of my src directory. Some online documentation suggested this should still be able to work, but I wasn’t able to figure it out before having to put it aside for some other priorities.

0reactions
pycnvrcommented, Jun 8, 2020

@chrispaterson Yes, I did some experiments with plugin-transform-runtime. My understanding is that there are two approaches. If the tcf libs are built with it, then tcf libs should specify @babel/runtime as a peer dependency. The client code then also add @babel/runtime as a dependency, and there is no need for babel to parse tcf again during client build. The downside is that client must also use plugin-transform-runtime instead of another polyfill such as the ones in preset-env. However, if tcf libs aren’t built with plugin-transform-runtime to begin with, then the approach above is still needed so babel can fix up codes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to load polyfills only when needed
I know three ready-to-use approaches for that: polyfill.io; the module / nomodule pattern; the useBuiltIns option in @babel/preset-env ...
Read more >
Polyfills, transpilation, and browser support | by Dominic Fraser
Yes, it is that exciting! Credit: Jopwell - The web is always changing - Who to support? - What is necessary to support...
Read more >
Polyfill - Cross-Browser Support for JavaScript Projects ...
A polyfill is a piece of code used to provide modern functionality on older browsers that do not natively support it. That is...
Read more >
Polyfill.io
It's a service which accepts a request for a set of browser features and returns only the polyfills that are needed by the...
Read more >
Browser support - Angular
The polyfills options of the browser and test builder can be a full path for a file (Example: src/polyfills.ts ) or, relative to...
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