Skip to content

Commit e91412b

Browse files
committed
Send origin referrer for YouTube embeds
Unfortunately, YouTube blocks embedded views in iframes that don't send a referrer. To fix them as-is, we explicitly provide the origin. A future implementation might offer a config option to either offer a YouTube video as iframe, requiring to send referrers towards Google, or provide just a link (with thumbnail), which requires no referrer, iframe or JavaScript. https://support.google.com/youtube/answer/171780#zippy=%2Cprovide-an-http-referrer-header-to-enable-video-playback https://developers.google.com/youtube/terms/required-minimum-functionality#embedded-player-api-client-identity
1 parent ee6cf6f commit e91412b

File tree

8 files changed

+9
-7
lines changed

8 files changed

+9
-7
lines changed

bridges/AnisearchBridge.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function collectData()
7272
$ytlink = <<<EOT
7373
<br /><iframe width="560" height="315" src="$trailer" title="YouTube video player"
7474
frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
75-
referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
75+
referrerpolicy="strict-origin" allowfullscreen></iframe>
7676
EOT;
7777
}
7878
}

bridges/AssociatedPressNewsBridge.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ private function processMediaPlaceholders($html, $id)
215215

216216
if ($media['type'] === 'YouTube') {
217217
$div->outertext = <<<EOD
218-
<iframe src="https://www.youtube.com/embed/{$media['externalId']}" width="560" height="315">
218+
<iframe src="https://www.youtube.com/embed/{$media['externalId']}" width="560" height="315" referrerpolicy="strict-origin">
219219
</iframe>
220220
EOD;
221221
}
@@ -251,7 +251,7 @@ private function processVideo($storyContent)
251251
if ($video['type'] === 'YouTube') {
252252
$url = 'https://www.youtube.com/embed/' . $video['externalId'];
253253
$html = <<<EOD
254-
<iframe width="560" height="315" src="{$url}" frameborder="0" allowfullscreen></iframe>
254+
<iframe width="560" height="315" src="{$url}" frameborder="0" allowfullscreen referrerpolicy="strict-origin"></iframe>
255255
EOD;
256256
} else {
257257
$html = <<<EOD

bridges/GizmodoBridge.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ private function handleIframeTags($html)
7676
{
7777
foreach ($html->find('iframe') as $iframe) {
7878
$iframe->src = urljoin($this->getURI(), $iframe->src);
79+
$iframe->referrerpolicy = 'strict-origin';
7980
}
8081
}
8182
}

bridges/GolemBridge.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private function extractContent($page, $prevcontent)
124124
$placeholders[$i]->innertext .= <<<EOT
125125
<iframe width="560" height="315" src="$link" title="YouTube video player" frameborder="0"
126126
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
127-
referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>';
127+
referrerpolicy="strict-origin" allowfullscreen></iframe>';
128128
EOT;
129129
break;
130130
}

bridges/HeiseBridge.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ private function addArticleToItem($item, $article)
213213
$ytiframe = <<<EOT
214214
<iframe width="560" height="315" src="https://$link[0] title="YouTube video player" frameborder="0"
215215
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
216-
referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
216+
referrerpolicy="strict-origin" allowfullscreen></iframe>
217217
EOT;
218218
//check if video is in header or article for correct possitioning
219219
if (strpos($header->innertext, $link[0])) {

bridges/ReutersBridge.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ private function handleArticleContent($contents)
543543
src="{$url}"
544544
frameborder="0"
545545
allowfullscreen
546+
referrerpolicy="strict-origin"
546547
>
547548
</iframe>
548549
EOD;

bridges/YouTubeCommunityTabBridge.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ private function getAttachments($details)
240240

241241
$content = <<<EOD
242242
<iframe width="100%" height="410" src="https://www.youtube.com/embed/{$attachments->videoRenderer->videoId}"
243-
frameborder="0" allow="encrypted-media;" allowfullscreen></iframe>
243+
frameborder="0" allow="encrypted-media;" allowfullscreen referrerpolicy="strict-origin"></iframe>
244244
EOD;
245245
} elseif (isset($attachments->backstageImageRenderer)) {
246246
// Image

bridges/YouTubeFeedExpanderBridge.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected function parseItem(array $item)
7676
}
7777
$embed = $embedURI . 'embed/' . $id;
7878
if ($this->getInput('embed')) {
79-
$iframe_fmt = '<iframe width="448" height="350" src="%s" title="%s" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>'; //phpcs:ignore
79+
$iframe_fmt = '<iframe width="448" height="350" src="%s" title="%s" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin" allowfullscreen></iframe>'; //phpcs:ignore
8080
$iframe = sprintf($iframe_fmt, $embed, $item['title']) . '<br>';
8181
$item['content'] = $iframe . $item['content'];
8282
}

0 commit comments

Comments
 (0)