Skip to content

YouTube Shorts / GDPR consent #543

Description

@TheDelta

In #326 the consent issue was described for YouTube (and Google Maps). and the fix is to fetch it over the API (requires token) or to use a custom plugin.

The latest version of iframely doesn't handle unfortunately YouTube shorts url.
My fix is to simply add the shorts url to the regex as well:

custom_plugins/domains/youtube.video.js

import * as plugin from './../../plugins/domains/youtube.com/youtube.video.js';

const fixedPlugin = { ...plugin.default };

fixedPlugin.re = [
    ...fixedPlugin.re,
    // add missing shorts support:
    /^https?:\/\/(?:www\.)?youtube\.com\/shorts\/([\w-]+)/i,
];

export default fixedPlugin;

but this will embed the short as a youtube video.

The other way to make it work (and display as embedded short) would be to set the cookie consent with the request.
Based on: https://stackoverflow.com/a/74132453/5152479

a new custom plugin custom_plugins/domains/youtube.short.js

// https://stackoverflow.com/a/74132453/5152479
const CONSENT_ACCEPT = 'CAISNQgDEitib3FfaWRlbnRpdHlmcm9udGVuZHVpc2VydmVyXzIwMjMwODI5LjA3X3AxGgJlbiACGgYIgLC_pwY';
const CONSENT_REJECT = 'CAESEwgDEgk0ODE3Nzk3MjQaAmVuIAEaBgiA_LyaBg';

export default {
    re: /^https?:\/\/(?:www\.)?youtube\.com\/shorts\/([\w-]+)/i,
    getData: function(options) {
        options.jar = { SOCS: CONSENT_REJECT };
    },
};

This will make the request with accepted consent and does the fetch like with an US based server and proper short embed.
But once youtube changes the format, this will most likely break.

Would be great to have some discussion and maybe a better solutions by the developers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions