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

Add a test for PermissionsPolicyViolationReportBody #856

Open
Elchi3 opened this issue Nov 16, 2023 · 0 comments
Open

Add a test for PermissionsPolicyViolationReportBody #856

Elchi3 opened this issue Nov 16, 2023 · 0 comments

Comments

@Elchi3
Copy link
Member

Elchi3 commented Nov 16, 2023

I couldn't find good docs on MDN about this :(
https://github.com/w3c/webappsec-permissions-policy/blob/main/reporting.md has some good info, though.

I reckon we need some custom test like below plus a way to actually trigger a permission policy violation.

  PermissionsPolicyViolationReportBody:
    __base: |-
      // Note: the Content-Security-Policy header is already configured on this website
      if (!('ReportingObserver' in self)) {
        return {result: false, message: 'ReportingObserver is not defined'};
      }

      // Create the observer
      var observer = new ReportingObserver(
        function(reports, observer) {
          var instance = reports.length && reports[0].body;
          callback(instance);
          observer.disconnect();
        },
        {
          types: ["permissions-policy-violation"],
          buffered: true,
        }
      );

      // Start observing
      observer.observe();
    toJSON: |-
      function callback(instance) {
        try {
          success(!!instance && 'toJSON' in instance);
        } catch(e) {
          fail(e);
        }
      }
      return 'callback';

PermissionsPolicyViolationReportBody ships in Chrome 120 and wasn't detected by our collector, see mdn/browser-compat-data#21148 (comment)

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

No branches or pull requests

1 participant