Allowing Web Share on Third-Party Sites
As of Safari Technology Preview 160, it is no longer possible to use the W3C’s Web Share API with third-party sites within an iframe without including an
allow attribute. All browser vendors agreed to this change as part of the W3C’s standardization process, and it is being rolled out in all major browser engines (including Chrome, Edge, Firefox, on mobile and desktop browsers).
The Web Share API allows web developers to enable the native sharing functionality of a device, such as sharing a link via email or social media. Prior to this change, the API could be used on any website within an iframe without restriction. However, due to concerns about privacy and security, browser vendors at the W3C have decided to limit the use of the API to only those sites that have explicitly been given permission to use it.
Web developers must now include an
allow attribute in the iframe HTML element to use the Web Share API within an iframe on a third-party site. The attribute accepts a value of
web-share and optionally the origin of the site that is allowed to use the API.
<iframe allow="web-share" src="https://example.com"> </iframe>
<iframe allow="web-share https://example.com" src="https://example.com"> </iframe>
allow attribute, the API will throw an exception and will not function within the iframe. The syntax of the
allow attribute is defined by the W3C’s Permissions Policy specification. You can learn more about the syntax on MDN.
This change is a necessary step in protecting user privacy and security. It helps ensure that the Web Share API is only used by sites that the developer signals is trustworthy. However, that means web developers will need to make some code changes to continue using the API within third-party iframes.