Skip to content

Feature request to expose fetch mechanism? #952

Open
@jfroelich

Description

@jfroelich

I am in a tight spot where I have to do a very strange setup in the browser. I have to embed segment within an iframe so as to ensure its globals are not messed with. There are multiple other third parties messing with globals, e.g. polyfills, hooked fetch function, incorrectly hooked functions, etc. In particular there is one strange third party hook that assumes that when the global identifier fetch exists that Request and friends also exist, which is not always the case in old browsers.

Embedding in an iframe is not ideal. I have 30kb of polyfill code in the top frame, and now I have to duplicate this polyfill code into the iframe. In particular, I have to do things like polyfill Promise.prototype.finally, which Segment uses but is not well supported in older browsers (e.g. Safari 10). I noticed that Segment is building with ts loader in one of examples, and that is problematic, because ts-loader does not transpile dependencies. I was doing this myself and had to switch to babel to get the dependencies transpiled once I uncovered the issue with the reliance on Promise.prototype.finally.

If, however, Segment provided a trivial way to specify the implementation of fetch to use (optional, default to current way it is done), then I could trivially plugin my own custom fetch function (I have one that uses a hidden iframe to get a clean fetch function). Alternatively it might be nice to just not have Segment assume it can rely upon the global fetch function or its unfetch fallback because in my case these are adulterated.

I cannot get rid of the third parties. It would be really awesome if I could specify the function to use during init. Then I could keep running Segment in the top frame and get rid of 30-40kb of duplicate polyfill code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions