Sec-Fetch-Dest header polyfill for Safari? #1004
Replies: 1 comment 2 replies
-
Hey, @andreawyss. It's nice to hear from you! According to the docs, the
You can try it out yourself: const req = new Request()
req.headers.set('Sec-Fetch-Dest', 'iframe')
req.headers.get('Sec-Fetch-Dest') // null The only legitimate source for this header is the browser itself. If it doesn't set it, there's nothing we can do to polyfill this on our side. Even if we could, I'm afraid this request falls outside of what MSW should do. It's, essentially, about adding a browser feature to the browsers that don't have it. It's not even related to mocking requests, only utilizing Service Workers to augment them. We are unlikely to consider such changes, as it's not the library's goal/promise. You can, however, write a custom worker that'd modify requests to your liking (hey, you can even compose workers with |
Beta Was this translation helpful? Give feedback.
-
Question
Could a service worker implement the
Sec-Fetch-Dest
header for Safari or add a different header when requests are initiated from an iframe vs. top window?Problem
Currently
Sec-Fetch-Dest
header is implemented by all browsers except for Safari and Safari on iOS.https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-Fetch-Dest
Solution
Write a service worker that adds a headers to all requests which value informs if request was initiated by a document inside an iframe or by the document in the top window.
Assumptions & Constrains
Top and iframe documents are on the same origin.
A same iframed document can also be loaded at the same time in a different browser's tab unframed (as a top document).
The server needs to generate a different page layout when a document will be shown by itself (Top document) or when shown inside an iframe.
We don't want to send the same document and then modify it on the client side based on top === self because the version for the iframe is faster to generate and puts less load on the server. The full version for the top window is heavier and slower to generate.
We can add code to the top document.
We can and add code to the iframed document.
Ask for Help
@kettanaito with your deep knowledge of service workers is there a way to achieve this?
Thank you for any help, suggestions or directions on what may be possible.
Beta Was this translation helpful? Give feedback.
All reactions