faker icon indicating copy to clipboard operation
faker copied to clipboard

Support older browsers without Proxy

Open Murreey opened this issue 1 year ago • 6 comments
trafficstars

We're using Faker in browser, and need to support older browsers that do not have Proxy (including all IE versions). As Faker relies on that for the LocaleProxy, it doesn't work in those browsers.

Is there any scope for Faker to be able to support those browsers? I don't have any suggestions for what that would be, but maybe some sort of browser feature detection or disabling the locale functionality.

Google's proxy-polyfill doesn't cover the has or deleteProperty handlers, so doesn't work for Faker's use case. (Unless an option is to stop using those handlers?)

Murreey avatar Oct 01 '24 15:10 Murreey

As for IE support: We wont add support for it in current versions of faker. Please try downgrading faker js/polyfilling and see whether it works. v6.1.2 is probably the last one without Proxy usage. IIRC: You can use the latest v7 for Proxy without has/delete.

Please note that old browsers will probably fail on other JS features we use as well.

Our code works on most modern browsers, if not please report any broken methods. (We had a bug in v9.0.0 where faker.image.dataUri() was broken in browsers.)

The somewhat planned faker v10 might be without the proxy behavior or at least could be triggered without it due to the standalone module functions.

  • #2667

ST-DDT avatar Oct 01 '24 16:10 ST-DDT

@Murreey, some questions from my side:

  1. Did you try to use an older version of faker as suggested? If yes, did it work?
  2. What error message do you get when you use google's polyfill with faker?

xDivisionByZerox avatar Oct 03 '24 15:10 xDivisionByZerox

@xDivisionByZerox

  1. Not yet, but we plan to! The API differences mean a bit of a migration for our prod code, but it does seem like it works from some quick tests.
  2. TypeError: Proxy polyfill does not support trap 'has', coming from here.

Murreey avatar Oct 03 '24 16:10 Murreey

2. TypeError: Proxy polyfill does not support trap 'has', coming from here.

Could you please open an issue in that repo, so they know it is a requested feature? Maybe one for has and another one for deleteProperty. And please link back here FFR.

ST-DDT avatar Oct 03 '24 18:10 ST-DDT

It's in maintenance mode unfortunately.

There's an issue #77 which is about a similar problem that might offer a solution though. Not certain, but I can't see anywhere in Faker that actually needs those handlers to work - making the polyfill ignore the error rather than throwing might be enough to at least get it working.

Murreey avatar Oct 03 '24 21:10 Murreey

If you need to support old browsers then running everything client-side may not be the best option. If it's a possibility for your application you could say run a tiny node.js server which exposes endpoints for the specific Faker data you need. Then it will work with any browser.

matthewmayer avatar Oct 03 '24 23:10 matthewmayer