polyfillpolyfill / polyfill-service

Automatic polyfill service.
https://polyfill.io/
MIT License
7.54k stars 756 forks source link

Callback not returned in device simulation #2853

Closed NicolaiNNielsen closed 3 months ago

NicolaiNNielsen commented 3 months ago

Bug report

What

When using device simulation using the Google Chrome web-inspector, the callback is not returned in the api response.

Details

In the attached screenshots i have shown the returned code from the same request url, but called from two different simulations in the developer tools (One being responsive mode, and one being a preset device from Chrome). Please note that some devices will work while others wont. When looking at the bottom of each response you will see that one includes the callback function and one dosen't.

image image

Environment Browser: Chrome 122.0.6261.112 Device: Macbook Pro M2 Max, Desktop

NicolaiNNielsen commented 3 months ago

Issue found

Turns out that the order of the query parameters matter which is not documented anywhere.

We solved above issue by setting the callback param as the first in the list, which is the same pattern as when generated within polyfill.io.

Dosen't work https://cdn.polyfill.io/v3/polyfill.min.js?flags=gated&features=default,es2015,es2016,es2017,es5,es6,es7,IntersectionObserver&callback=loadMainScript

Does work https://cdn.polyfill.io/v3/polyfill.min.js?callback=loadMainScript&flags=gated&features=default,es2015,es2016,es2017,es5,es6,es7,IntersectionObserver

Comment

If the CDN is so locked on the order of query parameters, it must be documented properly to avoid errors. Our callback where running the main.js file for the whole site, and since it was not returned and run, our site javascript was never triggered. I think the real solution should be to make the endpoint query order-agnostic

polyfillcust commented 3 months ago

both url is working now.