HTTP Permissions-Policy web-share

Typ

Die web-share-Direktive steuert den Zugriff auf die Web Share API für natives Betriebssystem-Share-Menü.

Syntax

Die Direktive definiert eine Allowlist für Ursprünge, die Web Share API verwenden dürfen.

http
Permissions-Policy: web-share=(self)
Permissions-Policy: web-share=(self "https://content.platform.com")
Permissions-Policy: web-share=()

Direktiven

Die Direktive unterstützt Standard-Allowlist-Werte für präzise Zugriffssteuerung.

self
Erlaubt Web-Share nur für das Hauptdokument des gleichen Ursprungs. Eingebettete iFrames von anderen Ursprüngen werden blockiert.
origin-list
Liste von Ursprüngen in Anführungszeichen, z.B. "https://reader.news-platform.example.com", die zusätzlich zum Hauptdokument Web-Share verwenden dürfen. Für Content-Reader-Widgets.

Beispiele

Die folgenden Beispiele zeigen typische Anwendungsfälle für Content-Sharing, Social-Media-Integration und Mobile-Apps.

News-App mit Native-Share-Button

Eine News-Anwendung nutzt Web Share API für natives Teilen von Artikeln.

http
HTTP/1.1 200 OK
Content-Type: text/html
Permissions-Policy: web-share=(self)

<!DOCTYPE html>
<html>
<head><title>Breaking News</title></head>
<body>
  <article>
    <h1>Article Title</h1>
    <p>Article content...</p>
  </article>
  <button id="share">Share Article</button>
  <script>
    document.getElementById('share').addEventListener('click', async () => {
      if (navigator.share) {
        await navigator.share({
          title: 'Article Title',
          text: 'Check out this article!',
          url: 'https://example.com/article/12345'
        });
      }
    });
  </script>
</body>
</html>

Content-Platform mit Embedded-Reader

Eine Content-Plattform erlaubt einem eingebetteten Reader-Widget Web-Share-Zugriff.

http
HTTP/1.1 200 OK
Content-Type: text/html
Permissions-Policy: web-share=(self "https://reader.content-platform.example.com")

<!DOCTYPE html>
<html>
<head><title>Reading List</title></head>
<body>
  <iframe src="https://reader.content-platform.example.com/article/789"
          allow="web-share"></iframe>
</body>
</html>

REST-API ohne Share-Funktion

Ein API-Endpunkt deaktiviert Web-Share für Backend-Services.

http
HTTP/1.1 200 OK
Content-Type: application/json
Permissions-Policy: web-share=()

{
  "status": "success",
  "article_url": "https://example.com/article/12345"
}

Vorteile für die Systemarchitektur

  • Ermöglicht natives OS-Share-Sheet für bessere Mobile-UX
  • Verhindert unerwünschten Share-Zugriff durch Drittanbieter-iFrames
  • Unterstützt direkte Integration mit System-Apps (WhatsApp, Mail, etc.)
  • Reduziert Abhängigkeit von Custom-Share-Button-Implementierungen

Spezifikation

Definiert in der W3C Web Share API Spezifikation. Erfordert HTTPS und User-Gesture. Primär Mobile-Browser-Support (Android, iOS).

Weitere Spezifikationen

Permissions-Policy Header, Content-Security-Policy Header