Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iframe small requested change #233

Closed
oferlaor opened this issue Jul 12, 2024 · 1 comment
Closed

Iframe small requested change #233

oferlaor opened this issue Jul 12, 2024 · 1 comment

Comments

@oferlaor
Copy link

oferlaor commented Jul 12, 2024

Some sites have restricted access on Media Embedding.

file: /s9e/text-formatter/src/Plugins/MediaEmbed/Configurator/TemplateGenerators/Iframe.php
One easy way to resolve this is to add a referrer policy, which tells the browser to restrict the referrer information when opening the IFRAME. This is dramatic as it opens up (particularly for youtube) a host of new videos that can be embedded.

	protected $defaultIframeAttributes = [
        'referrerpolicy'  => 'no-referrer-when-downgrade',
		'allowfullscreen' => '',
		'loading'         => 'lazy',
		'scrolling'       => 'no',
		'style'           => ['border' => '0']
	];
@JoshyPHP
Copy link
Member

I have considered setting a default referrer policy in the past, but I came to the conclusion this was best applied at the application level, most likely with a meta element.

Alternatively, if you want to set a referrerpolicy attribute on all iframe elements, you can do so via a template normalization. It should be created as early in the configuration as possible, before sites are added. For example:

$configurator = new s9e\TextFormatter\Configurator;
$configurator->templateNormalizer->add(
	new s9e\TextFormatter\Configurator\TemplateNormalizations\SetAttributeOnElements(
		'//iframe',
		'referrerpolicy',
		'no-referrer'
	)
);
$configurator->MediaEmbed->add('youtube');

extract($configurator->finalize());

$text = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
$xml  = $parser->parse($text);
$html = $renderer->render($xml);

die("$html\n");
<span data-s9e-mediaembed="youtube" style="display:inline-block;width:100%;max-width:640px"><span style="display:block;overflow:hidden;position:relative;padding-bottom:56.25%"><iframe allowfullscreen="" loading="lazy" scrolling="no" style="background:url(https://i.ytimg.com/vi/dQw4w9WgXcQ/hqdefault.jpg) 50% 50% / cover;border:0;height:100%;left:0;position:absolute;width:100%" referrerpolicy="no-referrer" src="https://www.youtube.com/embed/dQw4w9WgXcQ"></iframe></span></span>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants