faker
faker copied to clipboard
Support older browsers without Proxy
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?)
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
@Murreey, some questions from my side:
- Did you try to use an older version of faker as suggested? If yes, did it work?
- What error message do you get when you use google's polyfill with faker?
@xDivisionByZerox
- 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.
TypeError: Proxy polyfill does not support trap 'has', coming from here.
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.
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.
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.