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

Unrecognized feature: 'ambient-light-sensor' #298

Closed
dchimeno opened this issue May 26, 2022 · 6 comments · Fixed by #300
Closed

Unrecognized feature: 'ambient-light-sensor' #298

dchimeno opened this issue May 26, 2022 · 6 comments · Fixed by #300

Comments

@dchimeno
Copy link

Python Version

3.8

Django Version

3.2

Package Version

latest

Description

After setting the example:

PERMISSIONS_POLICY = {
    "accelerometer": [],
    "ambient-light-sensor": [],
    "autoplay": [],
    "camera": [],
    "display-capture": [],
    "document-domain": [],
    "encrypted-media": [],
    "fullscreen": [],
    "geolocation": [],
    "gyroscope": [],
    "magnetometer": [],
    "microphone": [],
    "midi": [],
    "payment": [],
    "usb": [],
}

Chrome shows:

Error with Permissions-Policy header: Unrecognized feature: 'ambient-light-sensor'.
@dchimeno dchimeno changed the title Error with Permissions-Policy header: Unrecognized feature: 'ambient-light-sensor'. Unrecognized feature: 'ambient-light-sensor'. May 26, 2022
@dchimeno dchimeno changed the title Unrecognized feature: 'ambient-light-sensor'. Unrecognized feature: 'ambient-light-sensor' May 26, 2022
@adamchainz
Copy link
Owner

It works for me!

I just tried with django 4.0.4 and django-permissions-policy 4.10.0, and the below single file app:

#!/usr/bin/env python
import html
import os
import sys

from django.conf import settings
from django.core.wsgi import get_wsgi_application
from django.http import HttpResponse
from django.urls import path

settings.configure(
    # Dangerous: disable host header validation
    ALLOWED_HOSTS=["*"],
    # Use DEBUG=1 to enable debug mode
    DEBUG=(os.environ.get("DEBUG", "") == "1"),
    # Make this module the urlconf
    ROOT_URLCONF=__name__,
    PERMISSIONS_POLICY={
        "accelerometer": [],
        "ambient-light-sensor": [],
        "autoplay": [],
        "camera": [],
        "display-capture": [],
        "document-domain": [],
        "encrypted-media": [],
        "fullscreen": [],
        "geolocation": [],
        "gyroscope": [],
        "magnetometer": [],
        "microphone": [],
        "midi": [],
        "payment": [],
        "usb": [],
    },
    MIDDLEWARE=["django_permissions_policy.PermissionsPolicyMiddleware"],
)


def index(request):
    name = request.GET.get("name", "World")
    return HttpResponse(f"Hello, {html.escape(name)}!")


urlpatterns = [
    path("", index),
]

app = get_wsgi_application()

if __name__ == "__main__":
    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)

@dchimeno
Copy link
Author

dchimeno commented May 27, 2022

I would say this is not about Django or django-permissions-policy and more about Chrome (or other browsers).

Just tried again running:

document.featurePolicy.allowedFeatures()

in the Chrome Console (Versión 102.0.5005.61 (Build oficial) (x86_64))

The ambient-light-sensor is not there. After searching for a while, you need to have activated the chrome://flags

#enable-generic-sensor-extra-classes

After that, the featurePolicy is allowed.

So probably doesnt set ambient-light-sensor in the examples is enough, or probably this doesnt need action at all.

@adamchainz
Copy link
Owner

Oh right, I missed that the error was from Chrome, I thought it was the check built in to the package.

I update the list of known features every quarter, I will do that now and update the example.

@adamchainz
Copy link
Owner

Huh, with Chrome Dev 104 I don't need to change a flag to see ambient-light-sensors. I'm on macOS. Is the message you see a warning or an error? I would guess that an unrecognized feature should just be a warning, and the other features should still be applied.

@dchimeno
Copy link
Author

It's just a warning in the Console.

I'm sure mantaining such a list is not gonna be a easy task, too many versions/variables.

@adamchainz
Copy link
Owner

If it's jsut a warning, it doesn't break anything, and it's kind of inevitable between browser versions. I'm adding a note in the docs about this in #298.

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

Successfully merging a pull request may close this issue.

2 participants