bing-translate-api icon indicating copy to clipboard operation
bing-translate-api copied to clipboard

Browser compatibility

Open dhowe opened this issue 4 years ago • 4 comments

Thanks for the nice library - I'm wondering if there is a way to use it in the browser? I've tried browserify, but got seems not to be compatible. Any suggestions?

dhowe avatar Oct 03 '21 12:10 dhowe

Thanks but I'm afraid we cannot use it in the browser. It's by mocking browser request with Node, however, the browser doesn't allow us to add some unsafe headers for the security. We have to run it in a server.

plainheart avatar Oct 03 '21 13:10 plainheart

What is the header that is not allowed in the browser (just curious)?

dhowe avatar Oct 03 '21 18:10 dhowe

The referer header and user-agent header etc. We can't change it at will in the browser.

plainheart avatar Oct 04 '21 06:10 plainheart

Would not replacing got with something like ky-universal, support both node and the browser?

dhowe avatar Oct 05 '21 03:10 dhowe

Actually, the referer doesn't matter, cookies don't matter, and the browser's own User Agent is fine. A few tweaks this can totally work inside a browser - but you do have to use a CORS anywhere proxy to get around the SOP. I have it working locally, I'll send a PR soon. You don't even need ky, plain browser fetch is sufficient.

infinity0 avatar Oct 04 '23 12:10 infinity0